-
Notifications
You must be signed in to change notification settings - Fork 6
Matching Cases
Giuseppe Lanza edited this page Aug 22, 2019
·
1 revision
EnumKit provides utilities functions for case matching.
Having a CaseAccessible enum
enum MyError: CaseAccessible, Error {
case notFound(String)
case noConnection(String)
case failedWithMessage(String)
}matching a case pattern can be achieved with matches(case:) function
let isConnectionIssue = myError.matches(case: MyError.noConnection) // Boolor with ~= swift pattern operator
let isConnectionIssue = myError ~= MyError.noConnection // Boolsimilarly negations are possible with the isNotMatching(case:) function or with the !~= pattern operator
// is not matching
let isNotConnectionIssue = myError.isNotMatching(case: MyError.noConnection) // Bool
let isNotConnectionIssue = myError !~= MyError.noConnection // Bool