Publishers.Decode
struct SimpleJSON: Decodable {
let key: String
}
let jsonData = "{ \"key\": \"value\" }".data(using: .utf8)!
// Publishers.Decode Publisher
Publishers.Decode<Just<JSONDecoder.Input>, SimpleJSON, JSONDecoder>(upstream: Just(jsonData), decoder: JSONDecoder())
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Decode Error")
case .finished:
print("Combine Decode Finish")
}
}, receiveValue: { value in
print("Combine Decode : \(value)")
})
.store(in: &cancellables)
// encode Operator
Just(jsonData)
.decode(type: SimpleJSON.self, decoder: JSONDecoder())
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Decode Error")
case .finished:
print("Combine Decode Finish")
}
}, receiveValue: { value in
print("Combine Decode : \(value)")
})
.store(in: &cancellables)
// Combine Decode : SimpleJSON(key: "value")
// Combine Decode FinishRxSwift
ReactiveSwift
Last updated