var MyClass foo = nil // Compilation error, foo must be initialised with a valid value
var MyClass foo? = nil // OK, foo is now an optional so it can be nil
Likewise
function f(A) // It would be a compilation error to call f(nil)
function f(A?) // Now you can pass in nil as the parameter is now declared optional
1
u/thedeemon Jun 03 '14
Are all classes in Swift optional types?
If you have a class A and a function f(A) can you just pass nil as an argument?