Iphone resourcePath在Xcode中不工作

Iphone resourcePath在Xcode中不工作,iphone,ios,xcode,ios5,Iphone,Ios,Xcode,Ios5,我已经为我的应用程序创建了一个包含数据的sqlite数据库,并将其拖到Xcode中的supporting files组中 当我尝试使用以下方式访问它时: NSString*bundlePath=[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@“database.db”] 它不读取文件。但是,如果我输入完整文件路径: NSString*bundlePath=@“Users/xxxx/Apps/App/databa

我已经为我的应用程序创建了一个包含数据的sqlite数据库,并将其拖到Xcode中的supporting files组中

当我尝试使用以下方式访问它时:

NSString*bundlePath=[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@“database.db”]

它不读取文件。但是,如果我输入完整文件路径:

NSString*bundlePath=@“Users/xxxx/Apps/App/database.db”

该应用程序运行良好


我从以下位置打印出文件路径:

NSString*bundlePath=[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@“database.db”]

它是:

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


知道为什么吗?

处理路径的最佳方法是让API处理关于“附加”路径字符串的细节

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

NSString*路径=[[NSBundle mainBundle]路径用于资源:@“数据库”
类型:@“.SQLite”]

当我尝试这样做时,path的计算结果为nil。在Xcode项目导航器(左侧)中选择上的文件,并确保在文件检查器(右侧)的“目标成员身份”下选中了目标还要仔细检查文件名的拼写。