Which Member Was Set?
After the sourceType
for UIImagePickerControllerSourceType
is set, how do you figure out which enum value was set? You use a switch
statement. Let’s go back to the suits in the deck of cards example. You will reuse the thisCardSuit
variable like so:
switch thisCardSuit {case .Hearts: println("was hearts")case .Clubs: println("was clubs")case .Diamonds: println("was diamonds")case .Spades: println("was spades")}// was clubs
Of course, this switch
statement must be exhaustive (see Chapter 1, “Getting Your Feet Wet”). This example prints out was clubs
.
Get Learning Swift™ Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.