问题
I'm trying to test my core data scheme. However, it seems I am unable to create the context because it says No visible @interface for 'MyAppDelegate' declares the selector 'managedObjectContext'
.
In online tutorials this method seems to be auto-generated when we create the app. However, in my case it doesn't exist.
This is MyAppDelegate:
Header
#import <UIKit/UIKit.h>
@interface MyAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
.m file
#import "MyAppDelegate.h"
@implementation MyAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSManagedObjectContext *context = [self managedObjectContext];
// Override point for customization after application launch.
return YES;
}
How should I fix this in Xcode 5 with iOS 7?
回答1:
I think the best way for you is to create a Master-Detail Application
with Xcode 5 and don't forget to check Use Core Data
:

With that, you will have an AppDelegate.h
and an AppDelegate.m
configured with a managedObjectContext
.
You will have a project configured correctly with Core Data and a .xcdatamodeld to use easily your SQLite database.
来源:https://stackoverflow.com/questions/19432058/no-managedobjectcontext-defined-in-my-appdelegate