[swift-users] enum compare

Quinn "The Eskimo!" eskimo1 at apple.com
Mon Jan 23 03:00:04 CST 2017


On 21 Jan 2017, at 12:56, tridiak via swift-users <swift-users at swift.org> wrote:

> How do I fix this? Simply cannot see it.

Use a switch statement:

switch type {
    case .noType, .dodge, .other: return true
    case .natural, .armour, .shield, .deflection, .sacred, .luck: return false
}

Note that I’ve spelt out all the cases so that the compiler warns me if I add or remove a case in the future.

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware




More information about the swift-users mailing list