How do i get rid of '-managedObjectContext' not found in protocol(s)
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]开发者_C百科 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 :)
Since -[UIApplication delegate]
returns an object of type id<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 to id
:
id appDelegate = (id)[[UIApplication sharedApplication] delegate];
managedObjectContext = [appDelegate managedObjectContext];
精彩评论