How to check if UserDefaults key exists in Swift?
Question
I wanna check if any specific UserDefaults key exists in the application, how to start with it?
Answer
The answer below is using Swift 3.
1 | func isKeyPresentInUserDefaults(key: String) -> Bool { |
When you use this function, simply create a variable by using1
let checkIfCookieExist = userAlreadyExist(KeyName: defaultsKeys.KeyName)
it will return a boolean.
Reference
This is the end of post