Xcode iPhone: property ... requires a method ... to be defined - use @syntehsize, @dynamic or provide an implementation of the method

in the .m file I have 4 warnings related to one command:

@end

  • The 'myHeader' property requires the definition of the '-myHeader' method - use @synthesize, @dynamic or provide an implementation of the method

  • The 'customCell' property requires the definition of the setCustomCell method: '- use @synthesize, @dynamic or provide an implementation of the method

  • The 'customCell' property requires the definition of the '-customCell' method - use @synthesize, @dynamic or provide an implementation of the method

  • The 'myHeader' property requires the definition of the setMyHeader method - use @synthesize, @dynamic or provide an implementation of the method

I have looked through the forums, but so far I am hopeless - can you explain to me (a novice programmer ...) how to debug it? Thanks a million!

+5
source share
7 answers

This means that you need to synthesize these variables. Synthesizing creates tuning and receiving methods for you. To do this, you need to include the following code in your implementation file (.m):

@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 if you don't want to do something specific, go to @synthesize.

+9
source

. , OP, , , - ( ) . , ( LLVM 4, @synthesize). , :

@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
+7

( .h) , -, - :

@property SomeClass *myHeader;
@property SomeClass *customCell;

, , , , . :

  • @implementation ( .m)

    @synthesize myHeader, customCell;
    

    . , .

  • :

    - (SomeClass *)myHeader
    {
        // Return the value of myHeader
    }
    
    - (void)setMyHeader:(SomeClass *)inMyHeader
    {
        // Set myHeader to inMyHeader
    }
    

    , .

  • @dynamic myHeader, customCell;, , . .

+5

@property , - "setter" "getter", , . , , - , . , (.h) :

@property(readwrite, assign) <type> myHeader;
@property(readwrite, assign) <type> customCell;

, setter getter, . . @synthesize, (.m) :

@synthesize myHeader;
@synthesize customCell;

@synthesize - myHeader, - setMyHeader, - customCell - setCustomCell . , .

Objective C.

+3

@property - , , getter setter, . :

  • -foo -setFoo:
  • @synthesize .m, .

.

0

ivars, @property, @synthesize. @synthesize .

0

, , , , , @synthesize.

.m , - @implementation,

@synthesize myHeader;

.

, -, myHeader. , . , .h, - @interface,

SomeType *myHeader;

, "SomeType" , , (, )

@property (retain) SomeType *myHeader;
0

All Articles