2010-08-27 22 views
0

我已經使用「use coredata」選項設置了我的項目。NSManagedObjectContext問題

的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 s沒有下劃線。

我的下一個問題是,我想在進一步使用上下文在我的腳本,我用這些行:

GFree2AppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 
context = delegate.managedObjectContext; 

現在,這是行不通的,因爲obvs有沒有@synthesize。但是我需要綜合什麼?我是否用下劃線進行綜合,或者沒有,我能得到它嗎? delegate.managedObjectContextdelegate.managedObjectContext_?還是根本不?哈..我不太清楚我是否理解所有這些管理對象的東西。

非常感謝。 湯姆

回答

0

下劃線只是一個偏好的風格,如果你願意,你可以用它或不合成它(但如果從聲明的屬性不同,你應在財產申報與getter=managedObjectContext例如

指定正確的名稱
+0

嗯....我剛剛刪除了下劃線的變量名的所有實例,並沒有下劃線替換。 – 2010-08-28 13:05:21

相關問題