0
我是Objective-C的新手,但添加通知观察者时遇到问题。我有一个类CoreDataStack,它是NSObject的一个子类。我正在尝试为iCloud同步添加通知观察器,但我一直在收到编译器错误。代码感并不在NSNotificationCenter上。据我所知,没有什么额外的我需要导入。我一定会错过一些非常明显的东西。将通知观察者添加到自定义类
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(persistentStoreCoordinatorStoresDidChange:)
name:NSPersistentStoreCoordinatorStoresDidChangeNotification
object:self.persistentStoreCoordinator];
- (void)persistentStoreCoordinatorStoresDidChange:(NSNotification*)notification {
NSLog(@"persistentStoreDidImportUbiquitousContentChanges");
}
下面是它给我的错误:缺少
- “[”的消息的发送开始表达
- 使用未声明的标识符“自我”
- 预计标识符或“(”的
你需要把你的调用注册到:'addObserver:selector:name:object:'in method * definition *,例如'-init','-viewDidLoad',等你有它在你的代码在这里的方式使它看起来像你试图** **定义的方法,当你真正想做的是**调用** 一个方法。 – fullofsquirrels
@fullofsquirrels哦,呃! – Morgan