0
RxAlamofireやAlamofireObjectMapperのようなライブラリをチェックする簡単なプロジェクトを作成しました。私は単純にApiService
と1つのエンドポイントがあり、適切に動作する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
をチェックしますそれはうまくいく;) – Michael