今天在用FMDB创建数据库的过程中出现DB Open Error 14 的错误,仔细分析是路径不正确。
-(instancetype)init{
if(self = [super init]){
NSString *doc =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject];
NSString *fileName = [doc stringByAppendingPathComponent:@"bluetooth.db"];
self.mDb = [FMDatabase databaseWithPath:fileName];
if([self.mDb open]){
[self needUpdate];
}
}
return self;
}
我的路径中少了斜杠/,因为我误用了stringByAppendingString,其实用了stringByAppendingString也没关系,只是需要自己手动添加斜杠。使用stringByAppendingPathComponent就不需要手动操作了。NSString *imagePath = [skinPath stringByAppendingString:[NSString stringWithFormat:@"/%@",imageName]]; //stringByAppendingString是在skinPath加后缀的意思 NSString *imagePath = [skinPath stringByAppendingPathComponent:imageName]; //stringByAppendingPathComponent是在skinPath后面加上“/”号连接imageName让它成为完整的路径 NSLog(@"imagePath:%@",imagePath);imagePath:/Users/will/Library/Application Support/iPhone Simulator/7.0.3/Applications/DA5B603D-4D07-4425-B7CC-5D49232189BE/Willing.app/tabbar_home.png