我想用 nil 履行 promise ,但我收到错误消息,我不能在这里是我的代码
public static func getCurrentDevice() -> Promise<Device>{
if let identity:[String:AnyObject] = auth?.get("identity") as! [String:AnyObject] {
if let uuididentity = identity["uuid"]{
return Promise { fulfill, reject in
Alamofire.request( Router.getDevice(uuididentity as! String) )
.responseObject { (response: Response<Device, NSError>) in
switch response.result{
case .Success(let data):
fulfill(data)
case .Failure(let error):
return reject(error)
}
}
}
}
}
return Promise { fulfill, reject in
fulfill(nil)
}
}
我得到编译器错误 无法使用类型为“((, _) -> _)”的参数列表为类型“Promise<>”调用初始化程序
最佳答案
如果 promise 没有返回值,你应该使用 ()
又名 Void
:
return Promise { fulfill, reject in
fulfill(())
}
如果这不起作用(我没有测试)你可以尝试注释它:
return Promise<()> { fulfill, reject in
fulfill(())
}
(请注意,()
是类型 ()
又名 Void
的唯一值)
关于ios - 如何快速履行零 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38213772/