2010-05-09 2 views
1

전 아이폰 개발에 뛰어 들고 있습니다. 어리숙한 질문이라면 사과드립니다.하지만 Core Data 프레임 워크를 사용하는 새로운 iPad 앱 프로젝트에서는 persistentStoreCoordinator를 생성하기 위해 생성 된 코드가 여기에 있습니다 ...iPhone 앱의 핵심 데이터 영구 저장소는 어디에서 찾을 수 있습니까?

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { 

if (persistentStoreCoordinator != nil) { 
    return persistentStoreCoordinator; 
} 

NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"ApplicationName.sqlite"]]; 

NSError *error = nil; 
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) { 
    /* 
    Replace this implementation with code to handle the error appropriately. 

    abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button. 

    Typical reasons for an error here include: 
    * The persistent store is not accessible 
    * The schema for the persistent store is incompatible with current managed object model 
    Check the error message to determine what the actual problem was. 
    */ 
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
    abort(); 
}  

return persistentStoreCoordinator; 

}

내 질문은 ...

  1. 내가 응용 프로그램을 처음 실행하면, 존재하지 않는 경우 자동으로 생성 된 ApplicationName.sqllite 데이터베이스가 무엇입니까? 그렇지 않다면 언제 만들어 집니까? 프로그래밍 방식으로 데이터를 추가 할 때?
  2. DB가 존재하면 어디에서 파일을 찾을 수 있습니까? 다른 프로그램으로 열어서 수동으로 데이터를 조작 할 수 있습니다.

도움을 위해 미리 감사드립니다. 지금 당장이 문제를 계속 연구 할 것입니다.

답변

4

예, 존재하지 않는 경우 ApplicationName.sqlite 데이터베이스가 생성됩니다. 그것은 귀하의 응용 프로그램의 Documents 디렉토리에 있습니다 (귀하의 -applicationDocumentsDirectory 메소드가 반환하는 것으로 가정).

시뮬레이터에서이 코드를 실행하는 경우 일반적으로 ~/Library/Application Support/iPhone Simulator 내에 응용 프로그램 데이터를 찾을 수 있습니다. 3.2+ SDK에서 다른 OS 버전은 특정 SDK를 사용하여 빌드 된 응용 프로그램을 그룹화하는 데 사용되므로 적절한 버전 디렉토리로 이동 한 다음 Applications으로 이동 한 다음 응용 프로그램의 숫자로 코딩 된 디렉토리를 찾아야합니다. -오류). Documents 디렉토리와 sqlite 데이터베이스가 거기에 있습니다.

장치에서 실행중인 경우 주최자로 이동하여 시스템에 연결된 상태에서 장치를 선택하고 요약 탭의 응용 프로그램 그룹으로 이동할 수 있습니다. 애플리케이션 이름 옆에있는 공개 화살표를 클릭하면 해당 애플리케이션 데이터를 디렉토리로 드래그하여 애플리케이션의 모든 작동 데이터를 기기의 애플리케이션 밖으로 가져올 수 있습니다.

+0

감사합니다. Brad, 하루 종일 큰 도움이되었습니다. – BeachRunnerFred

3

저장소는

addPersistentStoreWithType:configuration:URL:options:error: 

방법에 의해 생성된다.

NSLog(@"store path: %@", storeUrl); 

applicationDocumentsDirectory에있는 저장소의 파일 경로를 확인하십시오.

장치의 applicationDocumentsDirectory 전체를 다운로드하고 찾아 보려면 Xcode Organizer을 사용하십시오. 장치를 선택하고 응용 프로그램의 공개 삼각형을 클릭 한 다음 응용 프로그램 번들의 오른쪽에있는 화살표를 클릭하십시오.

관련 문제