They are not closed. These are anonymous properties because they are part of an anonymous category.
One of the things that are well suited for creating memory management semantics for an object belonging to it in one place. Consider this:
@property (nonatomic, assigned) NSString *assigned; @property (nonatomic, copy) NSString *copied; @property (nonatomic, retain) NSString *retained;
In all three cases, you can assign them this way without knowing what their semantics of memory are:
self.assigned = stringParameter; // assigns to instance variable self.copied = stringParameter; // copies, assigns copy to instance variable self.retained = stringParameter; // retains, assigns to instance variable
And in all three cases, you can clean up for free using the same code:
self.assigned = nil; // this just nils the instance variable self.copied = nil; // releases copy in ivar, nils instance variable self.retained = nil; // releases ivar (same as original object), // nils instance variable
That's why you often see local properties: it allows the encoder to skip writing all memory management logic every time they want to assign an instance variable. This main advantage is that you can change the memory management logic in the whole class by simply changing @property .
Another use of anonymous properties is to extend a property declared as readonly to external code as read / write for the class itself.
In .h:
@property (nonatomic, readonly, retain) NSError *lastError;
In .m, in the anonymous category:
@property (nonatomic, readwrite, retain) NSError *lastError;
Elsewhere .m code:
self.lastError = error;
Again, this is mainly due to memory management considerations.
An example related to using anonymous properties.
Here, every assignment to the _lastError instance variable looks without properties.
Suppose we have an NSError called _lastError defined in the .h file.
Saved:
[_lastError release]
With copy:
[_lastError release]
With purpose:
_lastError = error;
In the first two cases, you will need this in your dealloc:
[_lastError release]
But in the latter case, you must put nothing in dealloc or you will get a failure.
So add what you need to use the property:
Add this to the anonymous category:
@property (nonatomic, readwrite, retain) NSError *lastError;
Add this to @implementation:
@synthesize lastError = _lastError;
Please also note that at this point on the “modern” Cocoa run-time (64-bit Mac or iOS) you can remove NSError * _lastError from your header. The compiler can understand what you want based on @synthesize.
Here's how it changes our code:
Each appointment:
self.lastError = error; // works regardless of storage specifier
In daelloc:
self.lastError = nil;