Programming in Swift: Functions & Types

Jan 4 2022 Swift 5.5, iOS 15, Xcode 13

Part 4: Properties & Methods

32. Challenge: Properties

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See versions

See course reviews

See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 31. Lazy Properties Next episode: 33. Methods

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 kodeco.com Professional subscription.

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