Apple(Swift 2)示例包含以下代码:
// Coordinate reading on the source path and writing on the destination path to copy. let readIntent = NSFileAccessIntent.readingIntentWithURL(templateURL,options: []) let writeIntent = NSFileAccessIntent.writingIntentWithURL(target,options: .ForReplacing) NSFileCoordinator().coordinateAccessWithIntents([readIntent,writeIntent],queue: self.coordinationQueue) { error in if error != nil { return } do { try fileManager.copyItemAtURL(readIntent.URL,toURL: writeIntent.URL) try writeIntent.URL.setResourceValue(true,forKey: NSURLHasHiddenExtensionKey) NSOperationQueue.mainQueue().addOperationWithBlock { self.opendocumentAtURL(writeIntent.URL) } } catch { fatalError("Unexpected error during trivial file operations: \(error)") } }
setResourceValue(value:forKey :)似乎已被setResourceValues()取代,但我无法设置它.到目前为止我所拥有的是:
let readIntent = NSFileAccessIntent.readingIntent(with: templateURL,options: []) let writeIntent = NSFileAccessIntent.writingIntent(with: target,options: .forReplacing) NSFileCoordinator().coordinate(with: [readIntent,queue: self.coordinationQueue) { error in if error != nil { return } do { try fileManager.copyItem(at: readIntent.url,to: writeIntent.url) var resourceValues: URLResourceValues = URLResourceValues.init() resourceValues.hasHiddenExtension = true // *** Error on next line *** try writeIntent.url.setResourceValues(resourceValues) // Cannot use mutating member on immutable value: 'url' is a get-only property OperationQueue.main.addOperation { self.opendocumentAtURL(writeIntent.URL) } } catch { fatalError("Unexpected error during trivial file operations: \(error)") } }
除了Xcode“跳转到定义”之外,我找不到任何文档
Sets the resource value identified by a given resource key.
This method writes the new resource values out to the backing store. Attempts to set a read-only resource property or to set a resource property not supported by the resource are ignored and are not considered errors. This method is currently applicable only to URLs for file system resources.
URLResourceValues
keeps track of which of its properties have been set. Those values are the ones used by this function to
determine which properties to write.
public mutating func setResourceValues(_ values: URLResourceValues) throws
有没有人对setResourceValue(s)的变化有任何了解?
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。