问题描述
我正在尝试测试我的核心数据方案。但是,似乎我无法创建上下文,因为它说'MyAppDelegate'没有可见的@interface声明选择器'managedObjectContext'
。
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.
这是MyAppDelegate:
This is MyAppDelegate:
标题
#import <UIKit/UIKit.h>
@interface MyAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
.m文件
#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;
}
如何在iOS 7的Xcode 5中修复此问题?
How should I fix this in Xcode 5 with iOS 7?
推荐答案
我认为最好的方法是创建一个 Master-Detail Application
使用Xcode 5并且不要忘记检查使用核心数据
:
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
:
这样,您将获得 AppDelegate.h
和 AppDelegate.m
配置了 managedObjectContext
。
With that, you will have an AppDelegate.h
and an AppDelegate.m
configured with a managedObjectContext
.
您将使用Core Data和.xcdatamodeld正确配置项目,以便轻松使用您的SQLite数据库。
You will have a project configured correctly with Core Data and a .xcdatamodeld to use easily your SQLite database.
这篇关于我的AppDelegate中没有定义managedObjectContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!