Если ваш .h определен так:
@interface MDObject : NSObject {
NSMutableDictionary *properties;
}
@property (nonatomic, retain) NSMutableDictionary *properties;
@end
Ниже приведены возможные правильные реализации вашего .m:
@implementation MDObject
- (id)init {
if ((self = [super init])) {
properties = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void)dealloc {
[properties release];
[super dealloc];
}
@end
или
@implementation MDObject
- (id)init {
if ((self = [super init])) {
self.properties = [NSMutableDictionary dictionary];
}
return self;
}
- (void)dealloc {
self.properties = nil; // while this works,
// [properties release] is usually preferred
[super dealloc];
}
@end
Может быть полезно вспомнить, что
self.properties = [NSMutableDictionary dictionary];
совпадает с
[self setProperties:[NSMutableDictionary dictionary]];
Те 2 метода, которые для вас синтезированы, будут выглядеть примерно так:
- (NSMutableDictionary *)properties {
return properties;
}
- (void)setProperties:(NSMutableDictionary *)aProperties {
[aProperties retain];
[properties release];
properties = aProperties;
}