No managedObjectContext defined in my AppDelegate

北战南征 提交于 2019-12-31 06:48:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!