我如何摆脱“-managementObjectContext”在协议中找不到
我的应用程序在 iPhone 设备上运行,也在模拟器中运行。一切看起来都很好,但我在构建过程中看到编译器警告。我讨厌提供不完全正确的代码,所以我需要摆脱这个警告。编译器警告为:
newsReaderController.m:24: warning: '-managementObjectContext' not find in protocol(s)
代码为:
- (void)viewDidLoad {
[super viewDidLoad];
//CORE DATA
if (managedObjectContext == nil) {
managedObjectContext = [[[UIApplication sharedApplication] delegate] managedObjectContext];
}
}
CoreData 操作的 ManagedObjectContext 在 App Delegate 中设置。核心数据框架很重要,该应用程序运行起来就像一个魅力。
对我有什么提示吗?我已经使用 Objective-C 工作了几个星期了,但似乎每天都有新东西需要学习:)
my app runs on iPhone device and also in simulator. Everythings seems fine, but i see a compiler warning during build. I hate to deliver code thats not completely correct so i need to get rid of this warning. The compiler warning is:
newsReaderController.m:24: warning: '-managedObjectContext' not found in protocol(s)
The Code is:
- (void)viewDidLoad {
[super viewDidLoad];
//CORE DATA
if (managedObjectContext == nil) {
managedObjectContext = [[[UIApplication sharedApplication] delegate] managedObjectContext];
}
}
The managedObjectContext for CoreData operation is set up in App Delegate. Core Data Framework is importet and the app works like a charm.
any hint for me ? I'm working with objective-C for some weeks now but there seems to be something new to learn every day :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
-[UIApplication delegate]
返回id
类型的对象,编译器会抱怨该对象中不存在-managementObjectContext
方法协议。它就在那里,而且您也知道它在那里,因此您可以通过转换为委托的特定类型(MyAppDelegate
或任何可能调用的名称)或通过转换为id
:Since
-[UIApplication delegate]
returns an object of typeid<UIApplicationDelegate>
, the compiler is complaining that no-managedObjectContext
method exists in that one protocol. It's there, and you know it's there, so you can solve this issue by casting to your delegate's specific type (MyAppDelegate
or whatever it may be called), or by casting toid
: