我正试图在promise kit上链接一些承诺,当promise类型像Promise<Location>
时,我有语法问题,只有当promise有一个类型我得到编译器错误时。我是使用promisekit的新手
Swift.start(host,"","").then{ result -> Void in
}.then{ obj -> Void in
println(obj)
Swift.getCurrent.then{ obj -> Void in
let payload:Dictionary<String,AnyObject> = obj as! Dictionary<String,AnyObject>
self.deviceUUID = payload["uuid"] as! String
}
}.then { obj -> Location in
println(obj)
Swift.getLocation("3333").then{ location in
self.locationUUID = location.get("uuid")
}
}
答案 0 :(得分:0)
你的街区不需要退货:
.then { obj -> Location in
Swift.getLocation("433434").then{ location in
self.locationUUID = location.get("uuid")
}
}
答案 1 :(得分:0)
这里有很多问题。
Location
但闭包返回Void
。
Swift.start(host, "", "").then { result -> Void in
}.then { obj -> Promise<Something> in
print(obj)
// I changed the return of this closure, see above
// we must return the promise or we are not chaining
return Swift.getCurrent.then { obj -> Void in
let payload: Dictionary<String, AnyObject> = obj as! Dictionary<String, AnyObject>
self.deviceUUID = payload["uuid"] as! String
}
}.then { obj -> Location in
println(obj)
// we promised a return value above, so we must return
return Swift.getLocation("3333").then { location in
self.locationUUID = location.get("uuid")
}
}
然而,看看你的代码,看起来似乎不正确,这实际上是你所追求的吗?
firstly { _ -> Promise<[String: AnyObject]> in
return Swift.getCurrent
}.then { payload -> Promise<Location> in
self.deviceUUID = payload["uuid"] as! String
return Swift.getLocation("3333")
}.then { location -> Void in
self.locationUUID = location.get("uuid")
}