错误:0x0 Xcode 7.3.1的内存读取失败

时间:2016-09-03 14:07:54

标签: ios swift xcode7

使用以下代码运行XCTestCase(iPhone 6s和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"
}

}

一切看起来都很好,方法集(cpf :)的调用与预期的一样,但是set(rg :)会导致该错误。

不知道该怎么做,有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

Swift编译器似乎偶尔会出现问题,特别是如果你的代码使用了泛型。我使用Xcode 8.3.3对随机代码行进行了一次崩溃。清洁和建筑为我修好了。