문제

핵심 데이터가있는 Xcode 4에서 창 기반 iPhone 응용 프로그램을 만들었습니다.핵심 데이터 비트와 관련하여 몇 가지 질문이 있습니다.

  1. 응용 프로그램 위임 헤더 파일에서 3 개의 코어 데이터 속성이 인스턴스 변수로 나타나지 않는 3 가지 코어 데이터 속성이 없습니다.I.E. @Interface 섹션에 나열된 변수는 없지만 이들을위한 속성이 있으며 구현 파일에서 합성됩니다.이게 정확합니까?

  2. 기본 지속 메커니즘 SQLite?StoreURL이 "... urlbyappendingpathcomponent : @"coredataprojecttemplate.sqlite "

  3. 여기서 & & 언제 실제 SQLite 지속성 파일이 생성됩니까?이것이 템플릿에서 코드에서 볼 수 없습니까?이 코드를 추가하려면 자신의 코드를 추가해야합니까?

도움이 되었습니까?

해결책

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