I’m kinda new in Obj-C and I would like to ask why everything need to write something like this?
@property (_something, _something) NSString* name;
What is the @property indicates for?
Why we need to put _something in the bracket?
PS: I know there is no _something, it should be nonatomic, retain, copy and so on. Since it has so many options, that’s why I simply put a word to indicate the content inside the bracket.
(Where can I get all the list of available options?)
Thanks 😀
@propertyindicates that you are defining a property, which is at the basic level just syntactic sugar that allows you to dovariable = object.propertyandobject.property = valueinstead ofvariable = [object property]and[object setProperty:value]. If you really wanted, you could skip declaring any properties and just declare the getter and setter methods directly and the runtime would hardly notice the difference.The things inside the parentheses modify the property. Many are only useful for properties whose getter and/or setter implementations are created for you using
@synthesizein the @implementation block. For example,assign(the default) says that the value set is just set;retainsays that the object set will automatically have itsretainmethod called (and the previous object, if any, will havereleasecalled); andcopysays that the object will have itscopycalled.A list of possible attributes is in the documentation.