Compare to nil and return a bool in Swift

前端 未结 3 1241
旧巷少年郎
旧巷少年郎 2021-01-21 03:05

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 com

3条回答
  •  失恋的感觉
    2021-01-21 03:46

    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()
    }
    

提交回复
热议问题