Appleの"ShapeEdit"の例をSwift 3に変換しようとしていますが、URL
のsetResourceValue
への変更を自分の頭で行うことはできません。Swift 3のURLリソース値を設定しています
アップル(スウィフト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, writeIntent], 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「の定義にジャンプする」、以外のドキュメントを見つけることができません。このメソッドは、新しいリソース値をバッキングストアに書き込みます。読み取り専用のリソースプロパティを設定しようとしたり、リソースでサポートされていないリソースプロパティを設定しようとする試みは無視され、エラーとはみなされません。このメソッドは現在、ファイルシステムリソースのURLにのみ適用されます。
URLResourceValues
は、どのプロパティが設定されているかを追跡します。これらの値は、この関数がどのプロパティを書き込むかを決定するために使用される値です( )。
public mutating func setResourceValues(_ values: URLResourceValues) throws
誰もがsetResourceValue(s)
への変更に任意の洞察力を持っていますか?
新しいものを学ぶときには、古いものにはなく、エラーがあると想定します。あなたはほぼ正しいですが、 'intent.url'は読み取り専用なので、3行目は機能しません。しかし、このアイデアは、変更されたURLでインテントを正しく初期化することができます。 - intent = NSFileAccessIntent.writingIntent(:url、options:.forReplacing) 'あなたは答えを更新したいのですか?そうでしょうか? – Grimxn
代わりにあなた自身の答えを置き、私はこの1つを削除します:) – Sulthan
いいえ、あなたはそれを解決しました! – Grimxn