|
Hello, I've been practicing. Please see my two sets of codes. Both are structures for creating Player, and both could work. It seems Code 2 is neater ? ( is it common to use closure in a property ?) Code 1
Code 2
Thank you in advance, Boat |
|
The two structs are not quite the same. In the second struct, Adjust your test code to this and then try it with each of your
|
|
Oh
in code 2, it is computed property, so the created instance but in code 1, once the instance is created, Boat |
|
Yup. |
|
Forgot to mention... This achieves what you were probably trying to do with the second
You don't need an |
|
Hm...
Even if I change Right ? |
|
Correct, because it is assigned when the struct is created. If you use a |
|
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.