Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Beginning Swift

You're reading from   Beginning Swift Master the fundamentals of programming in Swift 4

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781789534313
Length 202 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Rob Kerr Rob Kerr
Author Profile Icon Rob Kerr
Rob Kerr
Kåre Morstøl Kåre Morstøl
Author Profile Icon Kåre Morstøl
Kåre Morstøl
Arrow right icon
View More author details
Toc

Challenge


We'll tie together a variety of Swift language techniques, giving you additional practice to create structs, functions, data types, and optionals, and use flow control structures.

To solidify your understanding of basic struct and class usage by practicing the creation of each type of object.

  1. Launch Xcode, and create a new playground, then save it to your desktop with the name Activity 5 - Final Activity.playground.

  2. Add the following enum, which will be used to classify customers by gold, silver, and platinum levels. Note that this enum has a rawValue of type String, which we will use while printing customer information:

    enum CustomerType:String {
        case silver = "SILVER"
        case gold = "GOLD"
        case platinum = "PLATINUM"
    }
  3. Create a new Customer struct with a set of String variables, including an optional for country and the variable type to classify the customer into one of the CustomerType categories:

    struct Customer {
        var name: String
      ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime