2010-05-09 12 views
1

我潛入iPhone的發展,所以我提前道歉,如果這是一個荒謬的問題,但在使用的核心數據框架的新的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. 一旦數據庫確實存在,我可以在哪裏找到該文件?我想用另一個程序打開它,以便我可以手動操作數據。

非常感謝您的幫助!我現在要繼續研究這些問題。

回答

4

是的,ApplicationName.sqlite數據庫將被創建,如果不存在。它將位於您的應用程序的Documents目錄中(假設這是您的-applicationDocumentsDirectory方法返回的內容)。

如果您在模擬器中運行此功能,您通常可以在~/Library/Application Support/iPhone Simulator中找到應用程序數據。在3.2+ SDK上,使用不同的操作系統版本對使用特定SDK構建的應用程序進行分組,因此您需要進入相應的版本目錄,然後找到Applications,然後找到應用程序的數字編碼目錄(幾乎可以通過試用和-錯誤)。 Documents目錄和sqlite數據庫將在那裏找到。

如果在設備上運行,您可以轉到管理器,選擇您的設備(連接到系統時),然後轉到摘要選項卡中的應用程序分組。單擊應用程序名稱旁邊的公開箭頭,然後可以將應用程序數據從那裏拖出到目錄中,以將應用程序的所有工作數據從設備上的應用程序中拉出。

+0

謝謝布拉德,你一整天都在幫忙! – BeachRunnerFred 2010-05-10 00:34:54

3

商店由

addPersistentStoreWithType:configuration:URL:options:error: 

方法創建的。使用

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

查看applicationDocumentsDirectory中商店的文件路徑。

要下載和瀏覽設備的整個applicationDocumentsDirectory,請使用Xcode Organizer:選擇您的設備,點擊應用程序的顯示三角形,然後點擊應用程序包右側的箭頭。

相關問題