我经常看到一个指向正在使用的可选错误变量的指针,就像在这段代码中一样:
if fileManager.fileExistsAtPath(path)
{
var error: NSError?
if !fileManager.removeItemAtPath(path, error: &error)
{
println("Error removing the file : \(error)")
}
}
我们为什么要这样做?
最佳答案
error 参数是一个输入
参数,可以设置error
的值而不是从函数返回它。在 Swift 上的 Apple iBook 中查找“输入”。
关于ios - 为什么我们在 Swift 中使用 &error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26862591/