resourcePath无法正常工作的Xcode [英] resourcePath not working Xcode

查看:55
本文介绍了resourcePath无法正常工作的Xcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含用于我的应用程序的数据的sqlite数据库,并将其拖到Xcode中的支持文件组中.

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";

该应用正常运行.

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

I printed out the file path from:

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处理有关将"内容添加到路径字符串的细节.

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"]; 

这篇关于resourcePath无法正常工作的Xcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆