开发者

Creating a directory seems to have a slight delay

In Cocoa, I've tried using -[NSFileManager createDirectoryAtPath:withIntermediateDirectories:attributes:error:] to create several directories in a row, making sure to create them in hierarchical order (so that subdirectories won't try to be created before their parent directories exist).

However, I no开发者_如何学运维tice that sometimes, not all of the subdirectories are created. Is there a delay to this method that maybe just isn't documented by Apple? Should I wait 0.1 seconds or something before assuming the directory exists (when it has no error)?


Are you catching the errors to make sure nothing is going awry? Also, I ran across this in the Apple docs the other day:

In iOS and Mac OS X v 10.5 and later you should consider using [[NSFileManager alloc] init] rather than the singleton method defaultManager. Instances of NSFileManager are considered thread-safe when created using [[NSFileManager alloc] init].

If you are using the defaultManager singleton, it might be worth it to allocate an instance and see if that resolves your problems.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜