2
假設我有一個這樣的類:如何觀察NSMutableArray中單個元素的變化?
@interface MyClass : NSObject
@property (nonatomic, strong, getter=theDataGetter) NSMutableArray* theData;
@end
@implementation MyClass
-(NSMutableArray *)theDataGetter
{
return [self mutableArrayValueForKeyPath:@"theData"];
}
@end
這裏,因爲海圖財產(其他志願complience方法是跳過),並通過mutableArrayValueForKeyPath我可以觀察插入志願complience的,更新,刪除數據屬性以上的操作。 現在假設這個數組包含可變字典。
self.obj = [[MyClass alloc] init];
_obj.theData = [[NSMutableArray alloc] initWithObjects:
[NSMutableDictionary dictionaryWithObjectsAndKeys:@"The one with glasses.",@"description",@"Manny",@"name", nil],
[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Looks a little like Governor Dewey.",@"description",@"Moe",@"name", nil],
[NSMutableDictionary dictionaryWithObjectsAndKeys:@"The one without a mustache.",@"description",@"Jack",@"name", nil],
nil];
現在的問題是如何觀察更改海圖陣列中的任何字典的「說明」項的值。假設我想觀察第一個對象的變化描述鍵的值與現在持有的不同。