ResourcePath does not work Xcode

I created a sqlite database containing data for my application and dragged it into a group of supporting files in Xcode.

When I try to access it using:

NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.db"];

It does not read the file. However, if I attach the full path to the file:

NSString *bundlePath = @"Users/xxxx/Apps/App/database.db";

The app works great.


I printed the file path:

NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.db"];

and this:

/Users/xxx/Library/Application Support/iPhone Simulator/5.1/Applications/EE614EFA-BAF9-478E-xxxx-xxxx/App.app/database.db

Any ideas why?

0
source share
2 answers

The best way to handle paths is to let the API take care of the details of "adding" material to the path lines.

 NSString *path = [[NSBundle mainBundle] pathForResource:@"database" ofType:@"db"]; 
+1
source

NSString * path = [[NSBundle mainBundle] pathForResource: @ "database" OfType: @ "SQLite"];

+1
source

Source: https://habr.com/ru/post/1480024/


All Articles