ios - 为什么我们在 Swift 中使用 &error?

标签 ios pointers swift

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

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/

相关文章:

ios - 当我尝试使用 userDefaults 保存到 ui 颜色时,Xcode 给我错误 : Fatal error: Unexpectedly found nil while unwrapping an Optional value

swift - 如何在 Swift Joint 中创建自定义链?

ios - 如何在ios7中获取当前高度

ios - 使用 UI 测试滚动单元格

c - 从 char 指针检索最后一组输入值

C sprintf 数组字符指针

ios - 导航栏中的中心图像

ios - 当 UIGravityBehavior 处于事件状态时,UIDynamicAnimator 拒绝达到平衡

c - 使用 C 动态存储文件中的信息

ios - OneSignal iOS SDK 发送通知失败代码 400