Publishers.Encode
μ λ€λ¦ ꡬ쑰체
μ΄λμ λΌμ΄μ λ λ κ°μ μΈμλ₯Ό λ°λλ€.
upstream
: μμμ νλ₯΄λ Publisherencoder
: μ¬μ©ν μΈμ½λ
encoder
λ Combineμ TopLevelEncoder
νλ‘ν μ½μ μ±νν΄μΌ νλλ°, νμ¬ JSONEncoder
μ PropertyListEncoder
κ° μ΄ νλ‘ν μ½μ μ±ννκ³ μλ€.
μμ μ€νΈλ¦Όμ μμλ₯Ό μΈμ½λ©νκΈ° μν΄ μ¬μ©ν μ μλ€.
encode
μ€νΌλ μ΄ν°μ κ΄λ ¨μ΄ μλ€.
struct SimpleJSON: Encodable {
let key: String
}
let simpleJSON = SimpleJSON(key: "value")
// Publishers.Encode Publisher
Publishers.Encode(upstream: Just(simpleJSON), encoder: JSONEncoder())
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Encode Error")
case .finished:
print("Combine Encode Finish")
}
}, receiveValue: { value in
print("Combine Encode : \(value)")
})
.store(in: &cancellables)
// encode Operator
Just(simpleJSON)
.encode(encoder: JSONEncoder())
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Encode Error")
case .finished:
print("Combine Encode Finish")
}
}, receiveValue: { value in
print("Combine Encode : \(value)")
})
.store(in: &cancellables)
// Combine Encode : 15 bytes
// Combine Encode Finish
μμ Publisherλ Encodable
νλ‘ν μ½μ λ°λ₯΄λ ꡬ쑰체μ μΈμ€ν΄μ€λ₯Ό λ°ννλ©°, JSONEncoder
λ₯Ό μ¬μ©νμ¬ μΈμ½λ©νλ€.
RxSwift
ν΄λΉ κΈ°λ₯μ ꡬννκΈ° μν μ€νΌλ μ΄ν°λ₯Ό μ 곡νμ§ μλλ€.
ReactiveSwift
ν΄λΉ κΈ°λ₯μ ꡬννκΈ° μν μ€νΌλ μ΄ν°λ₯Ό μ 곡νμ§ μλλ€.
Last updated
Was this helpful?