resourcePath not working Xcode

本秂侑毒 提交于 2020-02-08 05:58:50

问题


I have created a sqlite database containing data for my app, and dragged it into the supporting files group 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 put in the full file path:

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

The app works fine.


I printed out the file path from:

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

and it is:

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

Any ideas why?


回答1:


The best way to deal with paths is to let the API take care of the details about "appending" stuff to path strings.

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



回答2:


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



来源:https://stackoverflow.com/questions/11447010/resourcepath-not-working-xcode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!