Can you tell me the meaning of those custom accessors :
why would you add this info next to the setter :
@property (assign,getter=isSelected) BOOL selected;
and about the setter,
@property (copy,setter=setDefaultTitle:) NSString* title;
is this the same as writing @synthesize开发者_StackOverflow中文版 title=defaultTitle ?
Thanks
@property (assign,getter=isSelected) BOOL selected;
in your header file, specifies that you want to other classes to be able to use myObject.isSelected
to access this property. You're defining this name in the public interface to your class.
@synthesize title = defaultTitle;
in your implementation file, specifies that you have defined a property named title
for other classes to use, but internally to your class you want to actually use the name defaultTitle
. This is normally done when you have declared your own private instance variable named defaultTitle
which you don't want people modifying directly.
@property (assign,getter=isSelected) BOOL selected;
must specify the getter to conform to naming convention. See Apple's manual citation:
Typically you should specify accessor method names that are key-value coding compliant (see Key-Value Coding Programming Guide)—a common reason for using the getter decorator is to adhere to the isPropertyName convention for Boolean values.
@property (copy,setter=setDefaultTitle:) NSString* title;
It would be the same if you also specify the getter. You have to however use the @synthesize title = defaultTitle;
to generate the proper method names for your getter/setter methods.
精彩评论