Programming in Swift: Functions & Types

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

Part 4: Properties & Methods

32. Challenge: Properties

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: 31. Lazy Properties Next episode: 33. Methods

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: 32. Challenge: Properties

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

It’s time for some practice with properties. Again, everything you need is in the playground for this part of the course. Pause the video, and write some code to complete the exercises. Then, keep watching to compare your code with my solutions. Time to pause the video; have at it!

struct Temperature {
  var degreesF: Double
  var degreesC: Double
}
38 var degreesF: Double

  var degreesC: Double {
    get { return (degreesF - 32) / 1.8 }
  }
42 set { degreesF = newValue * 1.8 + 32 }
46 var temperature = Temperature(degreesF: 32)
temperature.degreesC
39     didSet {
      if degreesF > 100 {
        
      }
    }
41 print("It's \(degreesF) degrees Fahrenheit! I had fun coding in Swift with you before I melted.")
temperature.degreesC😺 = 75
func monthsUntilJingleBells(from month: Month) -> Int {
  Month.december.rawValue - month.rawValue
}
😺var🛑 monthsUntilJingleBells(from month: Month) -> Int {
var monthsUntilJingleBells😺: 🛑Int {
Month.december.rawValue - ❌month.❌rawValue
  😺var season: Season🛑 {
    switch 😺self🛑 {
Month.august.monthsUntilJingleBells
Month.august.season