Trần Hữu Hiền
Trần Hữu Hiền

Reputation: 1044

How to set UserDefaults time expire?

I used this code to store to UserDefaults. I want to know, how i can set time expire?

   static func _getByKey(_ key: String) -> Any? {
        UserDefaults.standard.string(forKey: key)
    }

    static func _setByKey(_ key: String, _ val: Any) {
        UserDefaults.standard.set(val, forKey: key)
    }

Upvotes: 0

Views: 844

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100503

There is no short way to do so , you need to store a timestamp and check it with the current one every app open to clear the keys / not

Upvotes: 1

Related Questions