Group Group Group Group Group Group Group Group Group

Programming in Swift · Properties | Ray Wenderlich

#1

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5994-programming-in-swift/lessons/41
0 Likes

#2

The video is stuck at the 8:40 mark? I tried reloading the webpage many times but can’t get the video to continue playing…

0 Likes

#3

It’s working over here mate. ( past 8:40 )
@renderingpixels

Have you tried another browser/device?

Grts,
Cera

0 Likes

#4

@renderingpixels Please let me know if you still have this issue when you get a chance. Thank you!

0 Likes

#5

I’m just going through this course now, and the video is not getting hung up. (Chrome v71).
I did however notice something else about this lesson, and a small issue with the supplied starter Playground.

The part where we call the ‘summonMagicalCreature’ function did not initially work for me. The problem is that the summonMagicalCreature.swift file is located in the Sources folder for the ‘Challenge - Properties’ page and not the ‘Properties’ page. I created a new file in the Sources folder of the ‘Properties’ page and copied and pasted the summonMagicalCreature code to get it to work.

0 Likes

#6

Thanks so much for letting us know! I updated the starter playground for this part and put summonMagicalCreature in the right place. :]

0 Likes

#7

I’m trying to understand better how set works. When exactly newValue is assigned to property? It is not explicitly done in the code. Is it when the closure runs till the end without calling return?

0 Likes

#8

set is the “assignment”. A computed property with both get and set is functionally the same (it’s just cleaner syntax) as having a set of methods, like this:

func getFullName() -> String {
  return "\(firstName) \(lastName)"
}

mutating func setFullName(_ newValue: String) {
  let nameSubstrings = newValue.split(separator: " ")

  guard nameSubstrings.count >= 2 else {
    print("\(newValue) is not a full name.")
    return
  }

  let nameStrings = nameSubstrings.map(String.init)
  firstName = nameStrings.first!
  lastName = nameStrings.last!
}

var fullName: String {
  get { return getFullName() }
  set { setFullName(newValue) }
}
0 Likes