1
내 앱에는 아래에서 볼 수있는 Restaurant
클래스가 있습니다. KVOController
을 첨부하고 싶습니다. 하지만 나는 운이 없다. 아래 코드를 첨부하면 충돌이 발생합니다.동기화 된 클래스에 KVO를 추가하는 방법은 무엇입니까?
FBKVOController *KVOController = [FBKVOController controllerWithObserver:self];
self.KVOController = KVOController;
[self.KVOController observe:self keyPath:@"[Restaurant current].name.asString" options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew block:^(id observer, id object, NSDictionary *change) {
DDLogDebug(@"Restaurant changed");
}];
이렇게 클래스에 KVO를 추가하는 가장 좋은 방법은 무엇입니까?
@implementation Restaurant
static Restaurant *current = nil;
+ (Restaurant *)current {
@synchronized(self) {
if (current == nil) {
current = [[Restaurant alloc] initWithId:0];
}
}
return current;
}
- (id)initWithId:(NSInteger)number {
self = [super init];
if (self)
{
...
}
return self;
}
@end