Combine操作符Matching示例


3个月前 124次点击 来自 移动端

标签: Swift

Matching 匹配

Matching 判断pipline的输出数据是否符合某个条件

allSatisfy/tryAllSatisfy

allSatisfy 在publisher发送完 .finished事件计算所有数据是否符合一定规则

["123", "345", "56"]
    .publisher
    .allSatisfy { value in
        value.count > 2
    }
    .sink { print($0) }

contains

contains 在publisher发送完 .finished事件后判断是否包含数据

["123", "345", "56"]
    .publisher
    .contains("123")
    .sink { print($0) }

containsWhere/tryContainsWhere

containsWhere/tryContainsWhere可自定义闭包,定义数据规则

["123", "345", "56"]
    .publisher
    .contains { value in
        value == "123"
    }
    .sink { print($0) }

Made with in Shangrao,China By Devler.

Copyright © Devler 2012 - 2022

赣ICP备19009883号-1