Home > AI > IOS > Combine >

ignoreOutput()

Example (Apple Official): ignore upstream values except completion

struct NoZeroValuesAllowedError: Error {
    
}

let cancellable = [1, 2, 3, 4, 5, 0, 6, 7, 8, 9].publisher
    .tryFilter({ anInt in
        guard anInt != 0 else { throw NoZeroValuesAllowedError() }
        return anInt < 20
    })
    .ignoreOutput()
    .sink(receiveCompletion: {print("completion: \($0)")},
          receiveValue: {print("value \($0)")})


// completion: failure(__lldb_expr_273.NoZeroValuesAllowedError())

Leave a Reply