views:

53

answers:

1

Hi there

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 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

A: 

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

rano
hmm.... i've just removed all instances of the variable name with the underscore and replaced without the underscore.
Thomas Clayson