When read a Swift project I could not understand the following code:
self.myTabbar?.addSubview(button)
In my opinion ,It should looks like this:
self.myTabbar!.addSubview(button)
Why it is correct to use ?
When read a Swift project I could not understand the following code:
self.myTabbar?.addSubview(button)
In my opinion ,It should looks like this:
self.myTabbar!.addSubview(button)
Why it is correct to use ?
When you use ! you must be sure that the variable is not nil, otherwise it crashes. In this case is correct to use ? because the addSubview method call it's executed only if the variable is not nil, in case it is nil it just skips that line.