var title: Double? = nil
var title2 = Optional<Double>.None
There is no difference, and there is nothing special about
For any type
T? is a (compiler built-in)
var value: T? var value: Optional<T>
Optional conforms to the
protocol, i.e. a value can be instantiated from the literal
var value: T? = nil var value: T? = .None var value: T? = Optional.None var value: T? = Optional<T>.None var value: T? = T?.None
are all equivalent. In the first three statements, the type
Optional<T> of the value on the right-hand side is inferred from the type annotation on the left-hand
side. The last two statements can be shortened to
var value = Optional<T>.None var value = T?.None
because the type is inferred automatically from the right-hand side.
Finally, since optionals are implicitly initialized to
all of the above statements are equivalent.