大佬教程收集整理的这篇文章主要介绍了swift3 – 在Swift 3中设置URL资源值,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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)") } }
有没有人对setresourceValue(s)的变化有任何了解?
以上是大佬教程为你收集整理的swift3 – 在Swift 3中设置URL资源值全部内容,希望文章能够帮你解决swift3 – 在Swift 3中设置URL资源值所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。