Programming in Swift: Functions & Types

Jan 4 2022 · Swift 5.5, iOS 15, Xcode 13

Part 3: Enumerations

22. Challenge: Enumerations

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 21. Enumerations Next episode: 23. Switch Statements

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 22. Challenge: Enumerations

Update Notes: This course was originally recorded in 2019. It has been reviewed and all content and materials updated as of October 2021.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

I’ve got a challenge to help you practice using enumerations! You’ll find everything you need on page 3 of the Playground for this part of the course, including some starter code! Pause the video, try the challenges on your own, and then come back to compare your work to mine.

enum Suit
enum Suit: String {

}
case heart
case club
case spade
case diamond
  case heart = "suit.heart.fill"
  case club = "suit.club.fill"
  case spade = "suit.spade.fill"
  case diamond = "suit.diamond.fill"
let heartIcon = Image(systemName: 😺Suit.heart.rawValue).resizable()
let clubIcon = Image(systemName: 😺Suit.club.rawValue).resizable()
let spadeIcon = Image(systemName: 😺Suit.spade.rawValue).resizable()
let diamondIcon = Image(systemName: 😺Suit.diamond.rawValue).resizable()
enum Coin
enum Coin: Double {

}
  case penny = 0.01
  case nickel = 0.05
  case dime = 0.10
  case quarter = 0.25
let coinPurse: [Coin]
 = [.penny, .penny, .dime, .quarter, .quarter, .nickel, .penny, .quarter]
let total = coinPurse.reduce(
.reduce(0.0) {
{ (result, coin) -> Double in
result + coin.rawValue