NSManagedObjectContext 问题
我已经使用“use coredata”选项集设置了我的项目。
XCode 显然会自动为我设置所有这些,现在我在应用程序委托头文件中有这些行:
@interface GFree2AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
GFree2ViewController *viewController;
UINavigationController *navController;
NSManagedObjectContext *managedObjectContext_;
NSManagedObjectModel *managedObjectModel_;
NSPersistentStoreCoordinator *persistentStoreCoordinator_;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet GFree2ViewController *viewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (NSString *)applicationDocumentsDirectory;
@end
我的第一个问题是,为什么托管对象和内容的初始指针有下划线?这就是它们在 .m 文件中的使用方式,但 @property
没有下划线。
我的下一个问题是,我想在我的脚本中进一步使用上下文,所以我使用了这些行:
GFree2AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
context = delegate.managedObjectContext;
现在这不起作用,因为 obvs 没有 @synthesize。但我需要合成什么?我是否使用下划线进行合成,或者不使用下划线进行合成,我能得到它吗? delegate.managedObjectContext
还是 delegate.managementObjectContext_
?或者根本没有?哈..我不太确定我理解所有这些托管对象的东西。
多谢。 汤姆
I've set up my project with the "use coredata" option set.
XCode obviously set all this up for me automatically, and now I have these lines in the app delegate header file:
@interface GFree2AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
GFree2ViewController *viewController;
UINavigationController *navController;
NSManagedObjectContext *managedObjectContext_;
NSManagedObjectModel *managedObjectModel_;
NSPersistentStoreCoordinator *persistentStoreCoordinator_;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet GFree2ViewController *viewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (NSString *)applicationDocumentsDirectory;
@end
My first question is, why do the initial pointers for the managed object and stuff have underscores? This is how they are used in the .m file and yet the @property
s have no underscores.
My next question is, I want to use the context further in in my script so I've used these lines:
GFree2AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
context = delegate.managedObjectContext;
Now this won't work because obvs there is not @synthesize. But what do I need to synthesize? Do I synthesize WITH the underscore, or without, and do I get it? delegate.managedObjectContext
or delegate.managedObjectContext_
? Or not at all? Ha.. I'm not too sure I understand all this managed object stuff.
Thanks a lot.
Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下划线只是一种偏好样式,如果您愿意,您可以使用它或不使用它进行合成(但如果它与声明的属性不同,您应该在属性声明中使用
getter=managementObjectContext
指定正确的名称例子The underscore is just a preference style, if you want you can synthesize with it or without it (but if it different from the declared property you shall specify the correct name in the property declaration with
getter=managedObjectContext
for example