I'm developing iOS App with FMDB(Database Library of using SQLite easily).
For creating a database named "test.db", I'm writing down the following code for making the path of the database.
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *paths = [manager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
NSString *documentDirs = [paths objectAtIndex:0];
NSString *writableDBPath = [documentDirs stringByAppendingPathComponent:@"test.db"];
When I tested with Xcode Simulator, I got the following error.
2014-07-13 21:27:44.084 ninethtest[1481:a0b] -[NSURL stringByAppendingPathComponent:]: unrecognized selector sent to instance 0x8a5fdd0
2014-07-13 21:27:44.095 ninethtest[1481:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL stringByAppendingPathComponent:]: unrecognized selector sent to instance 0x8a5fdd0'
Could you tell me how to solve this error.
You are mixing-up NSString
and NSURL
objects. You want:
NSURL *documentDirs = [paths objectAtIndex:0];
NSURL *writableDBPath = [documentDirs URLByAppendingPathComponent:@"test.db"];
and if the FMDB API requires an NSString
object for the database path, you can extract an NSString
object from an NSURL
object using:
NSString *writableDBPathString = [writableDBPath path];