0
我創建了簡單的項目來檢查像RxAlamofire和AlamofireObjectMapper這樣的庫。我有簡單的ApiService
與一個端點,其中PHP
腳本正常工作,並返回JSON
。我想打電話給recipeURL
,我用flatMap
運營商得到迴應,並提供給Mapper
我應該得到Recipe
對象。我該如何做到這一點?Swift 3,RxAlamofire和映射到自定義對象
或者有其他方法嗎?
class ApiService: ApiDelegate{
let recipeURL = "http://example.com/test/info.php"
func getRecipeDetails() -> Observable<Recipe> {
return request(.get, recipeURL)
.subscribeOn(MainScheduler.asyncInstance)
.observeOn(MainScheduler.instance)
.flatMap({ request -> Observable<Recipe> in
let json = ""//request.??????????? How to get JSON response?
guard let recipe: Recipe = Mapper<Recipe>().map(JSONObject: json) else {
return Observable.error(ApiError(message: "ObjectMapper can't mapping", code: 422))
}
return Observable.just(recipe)
})
}
}
ok Thx。我會檢查 – Michael
它工作thx;) – Michael