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?