Swift 承诺书语法链
我试图在promise kit上链接一些promise,当promise类型是这样时,我有语法问题,只有当promise有一个类型时,我才得到编译器错误。我对使用promisekit很陌生Swift 承诺书语法链,swift,swift2,promisekit,Swift,Swift2,Promisekit,我试图在promise kit上链接一些promise,当promise类型是这样时,我有语法问题,只有当promise有一个类型时,我才得到编译器错误。我对使用promisekit很陌生 Swift.start(host,"","").then{ result -> Void in }.then{ obj -> Void in println(obj) Swift.getCurrent.then{ obj -> Void in
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")
}
}
Swift.start(主机“,”)。然后{result->Void in
}.然后{obj->Void in
println(obj)
然后{obj->Void in
让有效负载:Dictionary=obj as!Dictionary
self.deviceUUID=有效负载[“uuid”]作为!字符串
}
}.然后{obj->中的位置
println(obj)
Swift.getLocation(“3333”)。然后{location in
self.locationUUID=location.get(“uuid”)
}
}
您的区块中不需要返回:
.then { obj -> Location in
Swift.getLocation("433434").then{ location in
self.locationUUID = location.get("uuid")
}
}
您不需要在您的区块中返回:
.then { obj -> Location in
Swift.getLocation("433434").then{ location in
self.locationUUID = location.get("uuid")
}
}
这里有很多问题
位置
,但闭包返回的是无效
Swift.start(主机“,”)。然后{result->Void in
}.然后{obj->Promise in
打印(obj)
//我更改了此关闭的返回,请参见上文
//我们必须兑现承诺,否则我们就不会被束缚
返回Swift.getCurrent.then{obj->Void in
让有效负载:Dictionary=obj as!Dictionary
self.deviceUUID=有效负载[“uuid”]作为!字符串
}
}.然后{obj->中的位置
println(obj)
//我们承诺返回值高于此值,因此我们必须返回
返回Swift.getLocation(“3333”)。然后{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")
}
首先在
返回Swift.getCurrent
}.然后{payload->Promise in
self.deviceUUID=有效负载[“uuid”]作为!字符串
返回Swift.getLocation(“3333”)
}。然后{location->Void in
self.locationUUID=location.get(“uuid”)
}
这里有很多问题
位置
,但闭包返回的是无效
Swift.start(主机“,”)。然后{result->Void in
}.然后{obj->Promise in
打印(obj)
//我更改了此关闭的返回,请参见上文
//我们必须兑现承诺,否则我们就不会被束缚
返回Swift.getCurrent.then{obj->Void in
让有效负载:Dictionary=obj as!Dictionary
self.deviceUUID=有效负载[“uuid”]作为!字符串
}
}.然后{obj->中的位置
println(obj)
//我们承诺返回值高于此值,因此我们必须返回
返回Swift.getLocation(“3333”)。然后{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")
}
首先在
返回Swift.getCurrent
}.然后{payload->Promise in
self.deviceUUID=有效负载[“uuid”]作为!字符串
返回Swift.getLocation(“3333”)
}。然后{location->Void in
self.locationUUID=location.get(“uuid”)
}
请发布您得到的编译错误。另外,您的第二个块应该返回一个Location对象。它不返回任何内容。AppDelegate.swift:43:15:无法使用类型为“((Location)->Location)”的参数列表调用“then”
,如何返回位置,语法是什么请发布您得到的编译错误。另外,您的第二个块应该返回Location对象。它不返回任何内容。AppDelegate.swift:43:15:无法使用类型为“((Location)->Location)”的参数列表调用“then”
,如何返回位置,syntax仍会有语法错误ViewController。swift:35:74:无法使用类型为“((u)->”的参数列表调用“then”“
我正在使用promise kit 2.2.1您的getLocation
方法是否返回promise
?我仍然存在语法错误ViewController。swift:35:74:无法使用类型为”(()->”的参数列表调用'then'
我正在使用promise kit 2.2.1您的getLocation
方法是否返回promise
?