错误是:调用中有额外的参数'writingItemAtURL‘
我正在为iOS开发Swift
我在Yosemite上使用Xcode 6.1.1
我尝试删除DerivedData并重启xcode,但没有任何帮助。
下面是一些游乐场代码来说明这个问题:
let movingOption = NSFileCoordinatorWritingOptions.ForMoving
let replacingOption = NSFileCoordinatorWritingOptions.ForReplacing
var testURL1 = NSURL(fileURLWithPath: "file1")
var testURL2 = NSURL(fileURLWithPath: "file2")
var error1: NSErrorPointer?
var error2: NSErrorPointer?
let fc = NSFileCoordinator(filePresenter: nil)
var result = false
fc.coordinateWritingItemAtURL(testURL1, options: movingOption, writingItemAtURL: testURL2, options: replacingOption, error: &error1, byAccessor: { (newURL1: NSURL, newURL2: NSURL) in
let fm = NSFileManager.defaultManager()
result = fm.moveItemAtURL(newURL1, toURL: newURL2, error: error2)
if !result {
println("DEBUG: Failed to move file \(moveError?.localizedDescription)")
}
})发布于 2014-12-17 11:24:01
将最后一行替换为:
fc.coordinateWritingItemAtURL(testURL1, options: movingOption, writingItemAtURL: testURL2, options: replacingOption, error: &error1) { (newURL1: NSURL, newURL2: NSURL) -> Void in
let fm = NSFileManager.defaultManager()
result = fm.moveItemAtURL(newURL1, toURL: newURL2, error: error2)
if !result {
println("DEBUG: Failed to move file \(moveError?.localizedDescription)")
}
}发布于 2014-12-18 04:20:12
我发现我犯了个愚蠢的错误。参数列表中的URL需要解包,因此工作代码如下所示:
let movingOption = NSFileCoordinatorWritingOptions.ForMoving
let replacingOption = NSFileCoordinatorWritingOptions.ForReplacing
var testURL1 = NSURL(fileURLWithPath: "file1")!
var testURL2 = NSURL(fileURLWithPath: "file2")!
var error1: NSError?
var error2: NSError?
let fc = NSFileCoordinator(filePresenter: nil)
var result = false
fc.coordinateWritingItemAtURL(testURL1, options: movingOption, writingItemAtURL: testURL2, options: replacingOption, error: &error1, byAccessor: { (newURL1: NSURL!, newURL2: NSURL!) in
let fm = NSFileManager.defaultManager()
result = fm.moveItemAtURL(newURL1, toURL: newURL2, error: &error2)
if !result {
println("DEBUG: Failed to move file \(error2?.localizedDescription)")
}
})https://stackoverflow.com/questions/27509599
复制相似问题