私はこれをやってしまった:
func equalName(_ expectedName: Notification.Name, condition: @escaping (([AnyHashable: Any]) -> Bool)) -> Predicate<[Notification]> {
return Predicate.define("equal <\(stringify(expectedName))>") { actualExpression, msg in
guard let actualValue = try actualExpression.evaluate() else {
return PredicateResult(status: .fail, message: msg)
}
let actualNames = actualValue
.filter { $0.name == expectedName }
.filter { notification in
guard let userInfo = notification.userInfo else {
return false
}
return condition(userInfo)
}
.compactMap { $0.name }
let matches = actualNames.contains(expectedName)
return PredicateResult(bool: matches, message: msg)
}
}
そして、呼び出しサイトで条件を提供できます..