Home > AI > IOS > Combine >

map(_:)

API

Example

import Foundation
import Combine

class Test {
    private var cancellable: AnyCancellable?
    
    init(){
        let numbers = [5, 4, 3, 2, 1, 0]
        
        let romanNumeralDict: [Int : String] = [1:"I", 2:"II", 3:"III", 4:"IV", 5:"V"]
        
        cancellable = numbers.publisher
            .map { romanNumeralDict[$0] ?? "(unknown)" }
            .sink { print("\($0)", terminator: " ") }
    }
}

let test = Test()

Leave a Reply