Programming in Swift: Functions & Types

Jan 4 2022 Swift 5.5, iOS 15, Xcode 13

Part 3: Enumerations

22. Challenge: Enumerations

Lesson Complete

Play Next Lesson
Save for later
About this episode
See versions

See course reviews

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

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've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a Professional subscription.

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 = ""
  case spade = "suit.spade.fill"
  case diamond = "suit.diamond.fill"
let heartIcon = Image(systemName: 😺Suit.heart.rawValue).resizable()
let clubIcon = Image(systemName: 😺
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