I want to fulfill a promise with nil but I get error message that I cant here is my code
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)
}
}
I get compiler error Cannot invoke initializer for type 'Promise<>' with an argument list of type '((, _) -> _)'
If the promise doesn't return a value you should use ()
aka Void
:
return Promise { fulfill, reject in
fulfill(())
}
If this doesn't work (I didn't test it) you could try annotate it:
return Promise<()> { fulfill, reject in
fulfill(())
}
(Note that ()
is the only value of type ()
aka Void
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With