Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

saving key and value pairs swift

I need a way to save key and value pairs in swift for my application. I am new to IOS programming, but I know Android and I am looking for something like shared preferences in android, but for swift. By "save," I mean that when the user quits out of the application, the key and value pairs are saved in the local data.

like image 398
dhruvm Avatar asked Feb 16 '15 17:02

dhruvm


1 Answers

Swift 3.0

Saving Data:

   let userDefaults = UserDefaults.standard
   userDefaults.set(yourKey, forKey: "yourKey")
   userDefaults.synchronize()

Reading Data:

 if let yourVariable: AnyObject = UserDefaults.standard.object(forKey: "yourKey") as AnyObject? { }
like image 148
mouness2020 Avatar answered Oct 22 '22 00:10

mouness2020