【发布时间】:2013-02-21 02:36:33
【问题描述】:
当我尝试使用下面的代码创建文件夹时,当我尝试创建一个已经存在的文件夹而不是返回 YES 时,它会返回 NO 并返回错误:
[[NSFileManager defaultManager] createDirectoryAtPath:[documentsPath stringByAppendingPathComponent:@"temp"] withIntermediateDirectories:NO attributes:nil error:&error];
Apple 的 documentation 说:
Return Value
YES if the directory was created or already exists or NO if an error occurred.
所以我应该在成功或文件夹存在时得到“是”。但是当文件夹存在时我收到此消息:
Error Domain=NSCocoaErrorDomain Code=516 "The operation couldn’t be completed. (Cocoa error 516.)" UserInfo=0x200ef5f0 {NSFilePath=/var/mobile/Applications/DA657A0E-785D-49B4-9258-DF9EBAC5D52A/Documents/temp, NSUnderlyingError=0x200ef590 "The operation couldn’t be completed. File exists"}
这是一个错误,应该报告给 Apple 还是我做错了什么?
【问题讨论】:
-
@trojanfoe:我确定。我已经重新安装了应用程序。第一次创建“临时”文件夹,但所有后续尝试都给我错误。
标签: ios directory nsfilemanager create-directory