首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我在尝试使用NSFileCoordinator的coordinateWritingItemAtURL()方法时遇到“额外参数”错误

我在尝试使用NSFileCoordinator的coordinateWritingItemAtURL()方法时遇到“额外参数”错误
EN

Stack Overflow用户
提问于 2014-12-17 00:41:43
回答 2查看 534关注 0票数 0

错误是:调用中有额外的参数'writingItemAtURL‘

我正在为iOS开发Swift

我在Yosemite上使用Xcode 6.1.1

我尝试删除DerivedData并重启xcode,但没有任何帮助。

下面是一些游乐场代码来说明这个问题:

代码语言:javascript
复制
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)")
    }
})
EN

回答 2

Stack Overflow用户

发布于 2014-12-17 11:24:01

将最后一行替换为:

代码语言:javascript
复制
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)")

    }
}
票数 0
EN

Stack Overflow用户

发布于 2014-12-18 04:20:12

我发现我犯了个愚蠢的错误。参数列表中的URL需要解包,因此工作代码如下所示:

代码语言:javascript
复制
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)")
    }
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27509599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档