【发布时间】: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:) 导致该错误。
不知道怎么办,谁能帮帮我?
【问题讨论】: