0
点赞
收藏
分享

微信扫一扫

IOS 开发学习十二 Bundle使用及文件引用

1.在xcode外创建一个文件夹,命令为app.bundle(必须为.bundle扩展名)

以后打开此文件夹,要鼠标右键-显示包内容,直接双击不行。

2.加到xcode项目里

3.代码获取里面文件路径:

资源路径:

NSString *bundlePath = [[NSBundle mainBundle] resourcePath];


文件路径:


NSString *url=[[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"app.bundle/datas.sqlite"];


上一级路径:

NSString *secondParentPath = [[bundlePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]


不通过bundle获取资源:

UIImage *img=[UIImage imageNamed:@"cellicon.png"];


获取自定义的文件路径:

NSString *newPath=[NSString stringWithFormat:@"%@%@%@",[[NSBundle mainBundle]resourcePath],@"/",@"test.txt"];
NSFileHandle *url2=[NSFileHandle fileHandleForReadingAtPath:newPath];



NSString *newPath=[[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"];
NSFileHandle *fileHandle=[NSFileHandle fileHandleForReadingAtPath:newPath];




举报

相关推荐

0 条评论