我已經創建了一個包含我應用程序數據的sqlite數據庫,並將它拖入Xcode中的支持文件組中。resourcePath不工作Xcode
當我嘗試使用訪問它:
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.db"];
它不讀取文件。但是,如果我把完整的文件路徑:
NSString *bundlePath = @"Users/xxxx/Apps/App/database.db";
的應用程序工作正常。
我打印出來的文件路徑:
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.db"];
,它是:
/Users/xxx/Library/Application Support/iPhone Simulator/5.1/Applications/EE614EFA-BAF9-478E-xxxx-xxxx/App.app/database.db
任何想法,爲什麼?
當我嘗試,路徑評估爲零。 – 2012-07-12 07:43:40
在Xcode Project Navigator(左側)中選擇該文件,並確保在File Inspector(右側)的「目標成員」下選中了目標。 - 再次檢查文件名稱的拼寫。 – Mundi 2012-07-12 07:45:47
謝謝讓它工作的人。 – 2012-07-12 07:47:41