NSUserDefaults - How to tell if a key exists

前端 未结 11 1814
耶瑟儿~
耶瑟儿~ 2020-12-12 11:06

I\'m working on a small iPhone app, and I am using NSUserDefaults as my data persistence. It only has to keep track of a few things, such as some names and som

11条回答
  •  既然无缘
    2020-12-12 12:00

    In Swift3, I have used in this way

    var hasAddedGeofencesAtleastOnce: Bool {
        get {
            return UserDefaults.standard.object(forKey: "hasAddedGeofencesAtleastOnce") != nil
        }
    }
    

    The answer is great if you are to use that multiple times.

    I hope it helps :)

提交回复
热议问题