Home > AI > Language > Swift >

guard

Example 1: guard and enum

enum State {
    case idle
    case loading
    case loaded
    case error
}

let a = State.idle

func test() -> State {
    guard case .loading = a else {
        return .error
    }
    return .idle
}

print(test())

Leave a Reply