Saving Data & Retrieving Data

Today I realised that it would be pretty neat to store some of the user settings in the phone app to maybe store the users score and where they got to should they close my game  unexpectedly.  After a little searching and checking the apple api documentation I found that there is a little database that is stored for each user called UserDefaults. You can store simple useful things here with very little code.

Some things may include User settings such as 

  • Sound
  • Volume
  • High Score
  • Name

Generally things that would be a pain in the ass to enter each time my game runs.

Example

let ud = UserDefaults.standard;
ud.set("my name is K", forKey: "name")
 ud.synchronize();

//Retrieving Information

         let ud = UserDefaults.standard;
        if let obj = ud.object(forKey: "name")
        {
            print(obj);
        }



Add comment

Loading
In 1957, the Earl launched an ultra thin watch to subvert the omega replica watches watchmaking world, and reinterpreted the definition of elegant watches. In this year, to celebrate the birth of the fake rolex watches replica 60th anniversary tab paragon, the grand launch of its present slim elegant concept Altiplano limited edition watch iwc watches series, the reappearance of extraordinary masterpiece.