3 ms·
This is very cool. For anyone who is not familiar with Swift, whatever property variable you declare (unless it's an optional) needs to be initialized in a cons
by rezashirazian 10y ago
This is very cool. For anyone who is not familiar with Swift, whatever property variable you declare (unless it's an optional) needs to be initialized in a constructor before the code can even compile.
With structs you get a default constructor that will take care of this for you, however when you define a class you need to take care of this yourself.
Because of this you can find yourself writing a lot of boilerplate code, setting variables in initializers. Having this process automated is something that Xcode has been lacking for sometime. (that and auto generating protocol methods when a class implements it)
struct sample:
http://imgur.com/a/wm5MO http://imgur.com/a/wm5MO
class sample:
http://imgur.com/a/CpWlk http://imgur.com/a/CpWlk
gist:
https://gist.github.com/kingreza/edd1b449ee3e34c4a9588e678af6d2c6 https://gist.github.com/kingreza/edd1b449ee3e34c4a9588e678af...