Swift has a narrow rule whereby a class with a designated initializer with no arguments is implicitly called by dereived class initializers if no other super.init call is specified and it is otherwise unambiguous. This is why you don’t need to explicitly call super.init() when subclassing NSObject, for example.
@IBDesignable and @IBInspectable
You can use two different attributes—@IBDesignable and @IBInspectable—to enable live, interactive custom view design in Interface Builder.
from Apple doc
Swift Ternanry Operator ?
This will cause a compiler error:
1 2 3 4 |
|
Putting spaces around operators will resolve the compiler error i.e.
let max = a > b ? a : b
Autorelease in Swift
In Swift it may be necessary to use autorelease
if we are using objective-c objects. e.g.
1 2 3 4 5 |
|
This is a clang doc regarding ARC and retain count. A lot of info to digest…
Swift Closure Error: Boolean Is Not Convertible to Void
This piece code here:
1 2 3 |
|
throws exception:
Cannot convert the expression's type 'Boolean' to type 'Void'
It is because if the block does not have a return statement, the compiler uses the result of the last statement as the return value
Adding a return ()
as the last expression to the block fixes the problem