我有一个现有的数据库文件。我想在项目中使用这个 db 文件。我将这个文件放在我的 mac 应用程序文件夹中,并将其拖到 Xcode 中。现在我已经编写了代码来检查文件是否存在。但它抛出 FALSE 异常。
bool databaseAlreadyExists = [[NSFileManager defaultManager] fileExistsAtPath:@"school.db"];
请告诉我如何使用现有的数据库文件。
谢谢
最佳答案
尝试获取路径
NSString *databasePath = [[NSBundle mainBundle] pathForResource:@"school" ofType:@"db"];
对于 swift :
let dbPath = Bundle.main.path(forResource: "school", ofType: "db")
关于iphone - 在xcode中访问数据库文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12672635/