O'Reilly logo

Learning Swift: Building an iOS Game by Jocelyn Harrigton, Christoffer Hallas, Clayton McIlrath, Paul Nettle, Ankur Patel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. Saving scores

Now that you are able to reach the end of the game, it’s time to save your scores on the device and brag about it by publishing the scores to GameCenter. In this chapter we cover saving score using the following:

  1. NSUserDefaults from UIKit
  2. Leaderboards from GameKit

NSUserDefaults is an old framework from back when NextStep was around, which is why the class is prefixed with NS. Even though it is old, it is a quick way to save small chunks of data.

GameCenter was introduced in iOS5 and offers a quick way to saves scores online on their servers so that the scores can be viewed through the Game Center application. Besides a leaderboard, Game Center can be used for turn based games and to record achievements in the game ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required