2012-08-06 15 views
3

我想了解如何在Xcode中使用绑定。我有这个类:此对象符合KVC吗?

#import <Foundation/Foundation.h> 

@interface OddsItem : NSObject { 
    NSMutableDictionary *properties; 
} 
@property(nonatomic, retain) NSMutableDictionary *properties; 

@end 

#import "OddsItem.h" 


@implementation OddsItem { 

} 
@synthesize properties; 

- (void)dealloc { 
    [properties release]; 
    [super dealloc]; 
} 

@end 

这是KVC兼容?我发现的例子似乎来自综合性质的日子之前。

如果它不符合KVC标准,我该怎么做才能做到这一点?

回答

3

@synthesized生成的方法是KVO兼容的。

只要您使用setter方法更改属性,它将符合KVO标准。

如果你直接改变实例变量,它不会。在这种情况下,您将不得不手动拨打willChangeValueForKey:didChangeValueForKey:

+0

当我重写我的'合成'的getter/setter方法时呢?在getter和setter中,我可以直接访问'_properties'吗? – hashier 2013-11-28 00:16:07