sdasdadas sdasdadas - 3 days ago 6
Swift Question

Do Optionals default to nil?

What is the initial value of the

delegate
variable if no constructor is provided?

class Example {
weak var delegate: Bool?
}

Answer

Yes it is automatically set to nil if unassigned.

From Apple:

If you define an optional variable without providing a default value, the variable is automatically set to nil for you

Comments