Created
April 25, 2019 12:54
-
-
Save GeekTree0101/9e55ecda04e7190102fbfaa76392fcb3 to your computer and use it in GitHub Desktop.
Easy Network Data -> Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxAlamofire | |
import Codextended | |
struct Model: Codable { | |
var id: Int | |
init(from decoder: Decoder) throws { | |
self.id = try! decoder.decode("id") | |
} | |
func encode(to encoder: Encoder) throws { | |
try encoder.encode(self.id, for: "id") | |
} | |
} | |
_ = RxAlamofire.requestData(.get, "https://api.github.com/repositories") | |
.asObservable() | |
.observeOn(MainScheduler.instance) | |
.map({ res -> [Model] in | |
let (_, data) = res | |
return try! data.decoded() ?? [] | |
}) | |
.map({ $0.first }) | |
.subscribe(onNext: { model in | |
print(model?.id) | |
let data = try? model?.encoded() | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment