Database Reference
In-Depth Information
ivar itself is not required because the property definition handles that for us,
as well. For example, if we had an object with the following header:
@interface MyObject : NSObject
{
NSString *myString; //Only required for a 32-bit application
}
@property (retain) NSString *myString;
@end
Xcode would interpret it the same as the following header:
@interface MyObject : NSObject
{
NSString *myString;
}
- (NSString*)myString;
- ( void )setMyString:(NSString*)string;
@end
In combination with the @property keyword, we have the @synthesize and
@dynamic keywords for use in our implementation files. @synthesize will generate
the actual accessors that the @property alludes to in the header. Therefore, in
our example MyObject.m file, we can declare the following:
#import "MyObject.h"
@implementation MyObject
@synthesize myString;
@end
and have the same effective code as this:
#import "MyObject.h"
@implementation MyObject
- (NSString*)myString;
{
return myString;
}
- ( void )setMyString:(NSString*)string;
{
@synchronized (self) {
if ([string isEqualToString:myString]) return ;
[myString release];
myString = [string retain];
}
}
@end
 
 
Search WWH ::




Custom Search