我是一名新开发人员,我收到此错误。我厌倦了通过两次添加 libsqlite3.0.dylib 并重新启动 x-code 来修复它。即使我添加了 libsqlite3.dylib 的另一个库,但没有工作。错误:由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法创建带有消息的可写数据库文件
-(void)copyDatabaseIfNeeded
{
NSFileManager * filemanger = [NSFileManager defaultManager];
NSError *error;
NSString *dbpath= [self getDbPath];
BOOL success = [filemanger fileExistsAtPath:dbpath];
if(!success)
{
NSString *defaultDBpath= [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"myDatabase.sqlite"];
success = [filemanger copyItemAtPath:defaultDBpath toPath:dbpath error:&error];
if(!success)
{
NSAssert1(0, @"Failed to create writeable database file with message '@' .", [error localizedDescription]);
}
}
}
-(NSString *)getDbPath
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [path objectAtIndex:0];
return[documentsDir stringByAppendingPathComponent:@"myDatabase.sqlite"];
}