Question

Consider following code:

@interface TestClass ()

@property NSString *privateProperty;

@end

Now, as I learned, to make to compiler also create the accessors, I have to add the @synthesize directive in the @implement-part.

But also, if don't add the directive, following message works:

[self setPrivateProperty:@"foo"];

From my understanding, this should lead to an error explaining me, that the selector is unknown. Why does this setter (and I think also the getter) still exist?

Was it helpful?

Solution

Since xcode 4.5 all properties will be synthesized automagically.

OTHER TIPS

The @property declaration declares the existence of the getter and setter methods. The @synthesize declaration creates implementations of those methods.

Before Xcode 4.5, you'd have got a compiler warning for omitting the @synthesize and a runtime crash - both caused by there being no implementation for the methods you'd implicitly declared.

As of Xcode 4.5, the implementation of the methods is automatically synthesized unless you specify otherwise (@dynamic).

It's a new feature introduced in a recent version of XCode: it auto-syntetize the property, creating an _propertyName ivar to store it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top