質問

Xcode 4にウィーンベースのiPhoneアプリケーションをコアデータで作成しました。コアデータビットに関して私はいくつかの質問をしています:

  1. アプリケーションのデリゲートヘッダファイルには、インスタンス変数として表示されない3つのコアデータプロパティがありませんか?すなわち@Interfaceセクションにリストされている変数はまだありませんが、それらのためのプロパティがあり、それらは実装ファイルで合成されます。これは正しいですか?

  2. デフォルトの永続化メカニズムSQLite?私は "StoreURLが" ... urlbyappendingpathComponent:@ "coredataprojecttemplate.sqlite" の "PersistentStoreCoordinator"メソッドで表示されます。

  3. ここで、実際のSQLite Persistanceファイルはいつ作成されますか?これがあるテンプレートからコードを見ることはできませんか?これを作成するためにあなた自身のコードを追加する必要がありますか?

役に立ちましたか?

解決

1 I assume you are referring to the following:

@synthesize managedObjectContext=__managedObjectContext;
@synthesize managedObjectModel=__managedObjectModel;
@synthesize persistentStoreCoordinator=__persistentStoreCoordinator;

This format allows you to create accessors for a variable of a different name (i.e. the getter / setter accessor names can be different from the variable name). If the variable has not been previously defined then the synthesize operation will automatically create a synthesized instance variable for you.

2 As you've inferred from the filename, the default persistent store for CoreData is SQLite; however it's not limited to this one type. When creating your persistent store for the first time you send a message to the persistentStoreCoordinator in which you set the addPersistentStoreWithType to one of the following:

NSSQLiteStoreType
NSBinaryStoreType
NSInMemoryStoreType

To be honest, unless you have a good reason to change it you're probably best just sticking with SQLite.

3 The location URL of the persistent store is built by establishing the directory that the application is executing within (with a message to applicationDocumentsDirectory - written elsewhere in your code) then appending the filename of the persistent store to it via the URLByAppendingPathComponent parameter. You can modify this to add sub-folders or changing the filename if you wish.

他のヒント

  1. The modern Objective-C runtime can synthesize not only accessors but also storage for properties. You can specify the ivars that back your properties yourself if you want to, or you can let the runtime figure it out.

  2. SQLite is the only backing store for Core Data supported in iOS.

  3. If I'm not mistaken, the file will get created (if it doesn't already exist) when the managed object context is saved. The URL is associated with the persistent store when it's added to the persistent store coordinator.

3) That storeURL is the name and location of the Core Data database. If you want to put it elsewhere just change the base directory. You may want to consider the Application Support directory.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top