为什么我们在Swift中使用&错误?

时间:2014-11-11 10:22:18

标签: ios pointers swift

我经常看到一个指向正在使用的可选错误变量的指针,就像在这段代码中一样:

if fileManager.fileExistsAtPath(path)
{
    var error: NSError?

    if !fileManager.removeItemAtPath(path, error: &error)
    {
        println("Error removing the file : \(error)")
    }
}

为什么我们这样做?

1 个答案:

答案 0 :(得分:3)

error参数是inout参数,可以设置error的值,而不是从函数返回它。查找" inout"在Apple的Swift iBook上。

相关问题