开发者

NSManagedObjectContext issues

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 @propertys 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 beca开发者_运维百科use 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜