Compare to nil and return a bool in Swift

swift

Solution

The under-the-covers method that Swift uses to turn non-`Bool` values in booleans for use in `if` statements is the `getLogicValue()` method of the `LogicValue` protocol (which `Optional` implements):

func hasLogin() -> Bool {
    return self.credential.getLogicValue()
}

Problem

UPDATE: This question is no longer a problem after Xcode beta5 Seems the beta3 release refactored how "nil" is working under the hood but didn't come with enough documentation. I have this piece of code works fine in beta2: ``` func hasLogin() -> Bool { return self.credentail != nil } ``` But in beta3, I got this error ``` Type 'NativeObject' does not conform to protocol 'NilLiteralConvertible' ``` `self.credential` is an optional value of 'Credential' protocol and implemented by NSObject subclass ``` @objc protocol Credential: NSObjectProtocol, NSCoding { } var credentail: Credential? ``` I could make it work by doing doubled negation like this, but it really looks ABSURD ``` func hasLogin() -> Bool { return !(!self.credentail) } ``` So is this a bug in Swift or I'm doing something wrong?

Original source