加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – Xcode单元测试和将数据写入磁盘

发布时间:2020-12-14 17:49:40 所属栏目:百科 来源:网络整理
导读:我正在尝试编写逻辑测试来调试将图像数据保存到磁盘的方法.我使用以下行将图像数据写入文档目录: docspath = [[NSString alloc] initWithString:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,TRUE) objectAtIndex:0]];fullp
我正在尝试编写逻辑测试来调试将图像数据保存到磁盘的方法.我使用以下行将图像数据写入文档目录:

docspath = [[NSString alloc] initWithString:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,TRUE) objectAtIndex:0]];
fullpath = [[NSString alloc] initWithFormat:@"%@/%@",docspath,_name]; 
BOOL written = [fileData writeToFile:fullpath options:NSDataWritingAtomic error:&dataerror];

除外,不写入数据,错误描述不返回此类文件或目录.我在iOS 5.1模拟器中的测试目标下运行此代码.我是否需要创建中间目录才能到达文档目录,或者在测试目标下写入磁盘还有其他问题吗?

错误返回:

2012-06-29 16:13:31.819 otest[4597:7b03] /Users/myaccount/xcode_projects/myproject/myproject/myfolder/MMFileManager.m - 285: Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x1e1e3a0 {NSUserStringVariant=Folder,NSFilePath=/Users/myaccount/Library/Application Support/iPhone Simulator/5.1/Documents/mmLogo.png,NSUnderlyingError=0x1e1b430 "The operation couldn’t be completed. No such file or directory"}

解决方法

单元测试不在您的应用程序中,因此,您无法在单元测试中访问Documents目录.

参考NSHomeDirectory in iPhone unit test

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读