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
2
3
func isKeyPresentInUserDefaults(key: String) -> Bool {
return UserDefaults.standard.object(forKey: key) != nil
}

When you use this function, simply create a variable by using

1
let checkIfCookieExist = userAlreadyExist(KeyName: defaultsKeys.KeyName)

it will return a boolean.

Reference


This is the end of post