hba
hba

Reputation: 7790

objective-c properties - no attribute

I've just started reading through the Object-c developer handbook from apple. I'm playing with properties. I declared a class interface which has two properties:

@interface SocialEnglish : NSObject <IsSociable>
@property int numberOfPeopleMet;
@property (readonly) int readOnlyProperty;
@end

without declaring the instance variable associated to the properties. To my surprise, the compiler didn't complain. Then I wrote a bunch of code to access the instance object and sure enough the setters and getters worked as if I had implemented them and associated them to instance variables!

In the declaring class I can do something like this:

...
_readOnlyProperty = 3;
...

hmmm...I gota say as helpful as this maybe...I don't like it. Why doesn't the compiler complain and instead generates code. Is there a setting I need to set.

Also please note that I don't have a @synthesize directive in my implementation class.

Thanks!

Upvotes: 0

Views: 161

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89509

The latest versions of Xcode automatically "synthesize" declared properties for you now. This came in with Xcode 4.0 (see the linked release notes under "Compiling: LLVM2.0").

If you want to call "@synthesize", or declare an "_readOnlyProperty" ivar or static and "@synthesize" to that, or write your own setters & getters, you can continue to do this.

Upvotes: 3

Related Questions