Publishers.MapKeyPath

μ œλ„€λ¦­ ꡬ쑰체 | ν‚€ 경둜의 값을 λ°œν–‰ν•˜λŠ” Publisher

μ΄λ‹ˆμ…œλΌμ΄μ €λ₯Ό μ œκ³΅ν•˜μ§€ μ•ŠλŠ”λ‹€.

νƒ€μž…μ˜ ν‚€ 경둜λ₯Ό 톡해 μ ‘κ·Όν•œ κ°’μœΌλ‘œ λ§€ν•‘ν•˜κΈ° μœ„ν•΄ μ‚¬μš©ν•  수 μžˆλ‹€.

map μ˜€νΌλ ˆμ΄ν„°μ™€ 관련이 μžˆλ‹€.

struct SomeStruct {
  let property = "value"
}

Just(SomeStruct())
  .map(\.property)
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine MapKeyPath Error")
    case .finished:
      print("Combine MapKeyPath Finish")
    }
  }, receiveValue: { value in
    print("Combine MapKeyPath : \(value)")
  })
  .store(in: &cancellables)

// Combine MapKeyPath : value
// Combine MapKeyPath Finish

SomeStruct ꡬ쑰체의 μΈμŠ€ν„΄μŠ€λ₯Ό λ°œν–‰ν•˜λŠ” μƒμœ„ Publisherλ‘œλΆ€ν„° property ν‚€ 경둜λ₯Ό 톡해 ν•΄λ‹Ή 값에 μ ‘κ·Όν•˜κ³  κ·Έ κ°’μœΌλ‘œ λ§€ν•‘ν•œλ‹€.

RxSwift

ν•΄λ‹Ή λ™μž‘μ„ κ΅¬ν˜„ν•˜κΈ° μœ„ν•œ μ˜€νΌλ ˆμ΄ν„°λ₯Ό μ œκ³΅ν•˜μ§€ μ•ŠλŠ”λ‹€.

ReactiveSwift

ν•΄λ‹Ή λ™μž‘μ„ κ΅¬ν˜„ν•˜κΈ° μœ„ν•œ μ˜€νΌλ ˆμ΄ν„°λ₯Ό μ œκ³΅ν•˜μ§€ μ•ŠλŠ”λ‹€.

Last updated