Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property requires method to be defined

I was converting a code from non-ARC to ARC, and removing some unnecessary @synthesize calls. One specific class started issuing warnings for some properties:

Class.h

@property (strong, nonatomic) NSString *xyz;

but when building, I get the warning.

Property 'xyz' requires method 'xyz'to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation

I thought that using Xcode 4.6 and and Default Apple LLVM compiler 4.2, the @properties should be auto-synthesized.

How do I tell the compiler to auto-synthesize the property? Do I have to use a specific project configuration to remove this warning?

like image 756
Gui Moura Avatar asked Feb 19 '13 17:02

Gui Moura


People also ask

How do you define a property in Objective-C?

If you declare an object/variable using @property, then that object/variable will be accessible to other classes importing its class. If you declare an object using @property in the header file, then you have to synthesize it using @synthesize in the implementation file.


1 Answers

Is this property on an NSManagedObject subclass? NSManagedObject disables auto-synthesis precisely because most declared properties are expected to be @dynamic.

This is accomplished with the NS_REQUIRES_PROPERTY_DEFINITIONS macro placed right before the @interface NSManagedObject, which expands to __attribute__((objc_requires_property_definitions)). This could be used on other classes too, but NSManagedObject is the only framework class I know of that does this.

like image 197
Lily Ballard Avatar answered Oct 19 '22 21:10

Lily Ballard