.none is one of the cases of the Optional enum.
Optional conforms to
NilLiteralConvertible, which lets you test any object against
Testing equality with
.none requires the object to conform to Equatable, or to subclass NSObject, which conforms to NSObjectProtocol, so implements
So you can ask
myClass == nil without doing anything special to MyClass, but you can’t test directly
myClass == .none unless Xcode knows how to test equality for MyClass objects.
Why would you test
== .none instead of
== nil? it’s more direct, and Ben Dietzkis wrote a post explaining why he sometimes prefers it:
it’s actually recommended to check if something !=.None(nil`), if you are certain there’s a possibility an object may be empty