GeneCode
GeneCode

Reputation: 7588

Why properties still work without synthesize?

I have in .h

@property (nonatomic) NSString *yourMom;

Then in .m

No synthesize! direct access in viewdidload:

_yourMom = @"Sally";

This works without synthesizing. Why?

Upvotes: 2

Views: 585

Answers (1)

Martin Le
Martin Le

Reputation: 719

Objective-C @properties are synthesized by default when not explicitly implemented.

Unless you specify otherwise, the synthesized instance variable has the same name as the property, but with an underscore prefix. For a property called firstName, for example, the synthesized instance variable will be called _firstName.

Please read this document from Apple. It has comprehensive information that you need.

Upvotes: 2

Related Questions