The symbol "@" is interpreted by the compiler as a directive. This is one of the Objective-C 'additions' to the C language. When you declare @property and then @synthesize, you instruct the compiler to create instructions and corresponding characters for getters and setters for you. Remember that in C, the operator "=" means "assign". In most cases, in the OO context provided by the Objective-C extensions, we work with pointers (also references) to isa data structures (classes in Objective-C).
Prior to Objective-C 2.0, all getter and setter methods had to be coded by the developer for each attribute, which in most cases was copy / paste code. To be fully compatible with KVC / KVO, it takes a lot of very tedious code ... willAccessValueForKey, doneUpdateValueForKey, etc., which the new compiler automatically adds for you when using the @ property / @ synhesize syntax. This is a huge productivity boost for developers. Adding point syntax to the language is a bit more controversial in the community, as it hides the magic that the compiler does from you to interpret the operator object.property = anotherObject.property; like [object setProperty:[anotherObject property]];
From Apple documentation referenced in other answers
Property Declaration Attributes
You can decorate a property with attributes using the @property form (attribute [, attribute2, ...]). Like methods, properties are tied to an interface declaration. For property declarations that use a comma-separated list of variable names, property attributes apply to all named properties.
If you use the @synthesize directive to inform the compiler of the creation of the access method (s), the code that it generates matches the specification given by the keywords. If you implement the access method yourself, you must make sure that it conforms to the specification (for example, if you specify a copy, you must make sure to copy the input value in the setter method).
falconcreek
source share