我有一个OS X应用程序,它存储应用程序范围的书签以持久访问某些目录.我能够毫无问题地写入这些目录,但是我的代码中有一部分我要进行额外的检查以确认路径是可写的并且失败了.
var fileManager: NSFileManager = NSFileManager.defaultManager()
var baseUrl: NSURL = try! NSURL(byResolvingBookmarkData: data, …)
var fileUrl: NSURL = url.URLByAppendingPathComponent("foo.txt")
// Changing this order has no effect, I make only the first start access call,
// the second one is to demonstrate that it's not working.
baseUrl.startAccessingSecurityScopedResource() // true
fileUrl.startAccessingSecurityScopedResource() // false
// File manager confirms that base path is writable, but anything inside
// it – not. This worked perfectly fine before sandboxing the app.
fileManager.isWritableFileAtPath(baseUrl.path!) // true
fileManager.isWritableFileAtPath(fileUrl.path!) …Run Code Online (Sandbox Code Playgroud)