in an .m file I have 4 warnings relating to one command:
@end
Property 'myHeader' requires method '-myHeader' to be defined - use @synthesize, @dynamic or provide a method implementation
Property 'customCell' requires the method 'setCustomCell:' to be defined - use @synthesize, @dynamic or provide a method implementation
Property 'customCell' requires method '-customCell' to be defined - use @synthesize, @dynamic or provide a method implementation
Property 'myHeader' requires the method 'setMyHeader' to be defined - use @synthesize, @dynamic or provide a method implementation
I browsed through forums but I am hopeless so far - can you explain to me (beginner programmer...) how to debug it? Thanks a million!
Resuscitating an old thread. Probably not the OP issue, but I thought it would be worth mentioning this, in case anyone else (like me) runs into this. You get the same message if you're implementing a new property in a class category (even puzzling if you're using LLVM 4 which no longer requires @synthesize). This is possible using the technique outlined here:
@interface SomeClass (Private)
@property (nonatomic, assign) id newProperty;
@end
NSString * const kNewPropertyKey = @"kNewPropertyKey";
@implementation SomeClass (Private)
@dynamic newProperty;
- (void)setNewProperty:(id)aObject
{
objc_setAssociatedObject(self, kNewPropertyKey, aObject, OBJC_ASSOCIATION_ASSIGN);
}
- (id)newProperty
{
return objc_getAssociatedObject(self, kNewPropertyKey);
}
@end
It means that you need to synthesize those variables. Synthesizing creates the setter and getter methods for you. To do this, you need to include the following code in your implementation (.m) file:
@synthesize myHeader;
@synthesize customCell;
Adding these lines should take care of your 4 errors.
You also have the option of defining the setter and getter methods yourself, but unless you want to do something specific, go with @synthesize for now.
In your class header (the associated .h file), you apparently have something resembling the following:
@property SomeClass *myHeader;
@property SomeClass *customCell;
This tells the compiler that you want your class to have these properties, but you still have to tell it how to get and set the values on instances. You have three options:
In the @implementation section (in the .m file), you can add
@synthesize myHeader, customCell;
to tell the compiler to automatically generate methods to get and set these properties. This is the easiest and usually what you want.
You can implement the methods yourself like so:
- (SomeClass *)myHeader
{
// Return the value of myHeader
}
- (void)setMyHeader:(SomeClass *)inMyHeader
{
// Set myHeader to inMyHeader
}
This is generally used for derived or dynamically generated properties, or when you want to do extra work when they're changed.
You can use @dynamic myHeader, customCell;
to tell the compiler that implementations will be provided at runtime. This is rarely used.
Using @property
tells the compiler that you intend to access the corresponding member variable through "setter" and "getter" functions, i.e. functions which change the value of the variable or return its value. The warnings you're seeing are because you have not defined the required functions. I'm guessing your header (.h) file looks something like this:
@property(readwrite, assign) <type> myHeader;
@property(readwrite, assign) <type> customCell;
Because you've told the compiler that those variables should be accessible through setter and getter functions, you need to define those functions. There are two ways of doing this. The easiest is to use @synthesize
, by adding the following to your implementation (.m) file:
@synthesize myHeader;
@synthesize customCell;
The @synthesize
line causes the - myHeader
, - setMyHeader
, - customCell
and - setCustomCell
methods to be generated automatically at compile time. You may also define those methods manually, but doing so is usually unnecessary.
Here's a page with more information about properties in Objective C.
You have two ivars defined in @property statements, but you're missing the matching @synthesize statement. Add the @synthesize to the class definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With