evgenyneu / keychain-swift

Helper functions for saving text in Keychain securely for iOS, OS X, tvOS and watchOS.
MIT License
2.82k stars 345 forks source link

How to know if the given key exists? #104

Closed gauravrai1 closed 5 years ago

evgenyneu commented 5 years ago

Hi @ThinkHattke, there is no way to check if a key exist with this library. However, you can check if there is non-nil value saved for your key:

let keychain = KeychainSwift()
let value = keychain.get("my key")

if value == nil {
   print("No value")
}
gauravrai1 commented 5 years ago

Hi @evgenyneu, thanks for the solution, But it throws an error while building the app, but then I figured out a way.

`let keychain = KeychainSwift()

let logged = keychain.getBool("logged") ?? false`

This provided me the values without modifying any dataType.