【问题标题】:error: memory read failed for 0x0 Xcode 7.3.1错误:0x0 Xcode 7.3.1 的内存读取失败
【发布时间】:2016-09-03 14:07:53
【问题描述】:

我在使用以下代码运行 XCTestCase(iPhone 6s plus iOS 9.3)时遇到此错误:

        let x = user as! ClientUser
        x.set(cpf: CPF(cpf: self.makeRandomCPF())!)
        let rg = self.requestId().id // this line was for debugging purposes
        let rgrg = RG(rg: "\(rg)") // this line was for debugging purposes
        let rgString = rgrg!.toString() // this line was for debugging purposes
        let id = x.id.id // this line was for debugging purposes
        x.set(cpf: nil) // this line was for debugging purposes
        x.set(rg: nil) // this is the line where the error occurs

ClientUser 类定义为:

public class ClientUser: User {

// MARK: -Methods
public func set(cpf cpf: CPF?) -> Future<Bool, NSError> {
    let promise = Promise<Bool, NSError>()

    if let cpf = cpf {
        UserFactory.singleton.exists(cpf: cpf)
            .onSuccess(callback: { exists in
                if exists {
                    promise.failure(AlreadyExistsException(domain: "User.ClientUser.set(cpf:)", code: 0, userInfo: ["error": "AlreadyExistsException"]))
                }
                else {
                    self.cpf = cpf
                    promise.success(true)
                }
            })
            .onFailure(callback: { error in
                promise.failure(error)
            })
    }
    else {
        self.cpf = nil
        promise.success(true)
    }

    return promise.future
}

public func set(rg rg: RG?) -> Future<Bool, NSError> {
    let promise = Promise<Bool, NSError>()

    if let rg = rg {
        UserFactory.singleton.exists(rg: rg)
            .onSuccess(callback: { exists in
                if exists {
                    promise.failure(AlreadyExistsException(domain: "User.ClientUser.set(rg:)", code: 0, userInfo: ["error":"AlreadyExistsException"]))
                }
                else {
                    self.rg = rg
                    promise.success(true)
                }
            })
            .onFailure(callback: { error in
                promise.failure(error)
            })
    }
    else {
        self.rg = nil
        promise.success(true)
    }

    return promise.future
}

override class public var className: String {
    return "ClientUser"
}

}

一切看起来都很好,方法 set(cpf:) 被按预期调用,但 set(rg:) 导致该错误。

不知道怎么办,谁能帮帮我?

【问题讨论】:

    标签: ios swift xcode7


    【解决方案1】:

    Swift 编译器似乎不时出现问题,尤其是在您的代码使用泛型的情况下。我使用 Xcode 8.3.3 在随机的代码行上一直发生这种崩溃。清洁和建造为我修复了它。

    【讨论】:

      猜你喜欢
      • 2019-10-07
      • 2021-12-27
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多