When subclassing UIViewController ( and other similar classes ) we do not have to deal with any initialization, so if I create a stored property that is not an optional, Xcode will complain that there are no initializer.
So how can I create a non-optional store property in these classes? or should I?
You have 2 options:
initialize it inline
var myProp = MyClass()
declare it as implicitly unwrapped optional:
var myProp: MyClass!
and initialize it anywhere in the view controller - usually in viewDidLoad. This is the pattern commonly used for outlets, and one of the few cases where I tolerate implicitly unwrapped
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With