Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-14-2011, 03:33 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 19
Franhu is on a distinguished road
Default Save Highscore in Plist-File!

Hi all!

If i want to save perhaps the best 15 scores the user reached in my game. whats's the best solution? i thought i would save the scores in an array and save the array to a .plist file.
after i closed the app (double klick on home-button and then close the app) and launch it again, then i can load the data from the plist file. is this correct?


thx for help!


Franhu
Franhu is offline   Reply With Quote
Old 12-14-2011, 09:26 AM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Wrap the scores in NSNumbers and store them in an array. Then use NSUserDefaults to save them.
Code:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:yourArray forKey:yourHighScoreArrayKey];
[prefs syncronize];

NSArray *highScoreArray = [prefs objectForKey:yourHighScoreArrayKey];
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 12-14-2011, 01:59 PM   #3 (permalink)
iPhone is my sword
 
Join Date: Dec 2011
Location: Conquering the world
Posts: 9
bonaparte is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Wrap the scores in NSNumbers and store them in an array. Then use NSUserDefaults to save them.
Code:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:yourArray forKey:yourHighScoreArrayKey];
[prefs syncronize];

NSArray *highScoreArray = [prefs objectForKey:yourHighScoreArrayKey];

Hey Domele, good to see you again, been learning a lot watching tuts on youtube.

Here is my question, what would be the best way to simplify that code to produce two utility functions like:

saveUserPreferences(scores,"scoreboard")
scores = loadUserPreferences("scoreboard")

and where to put that library for reuse in future projects? Should I create a utils.h/m file and include them in my projects whenever I need that functionality? What would it be your approach to simplify stuff?
bonaparte is offline   Reply With Quote
Old 12-14-2011, 04:59 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

I'd create a ScoreBoard data class that has an internal scoreboard array. Then give it methods like addScore:forName: and allScores. Whenever someone calls addScore:forName: or whatever method name you choose that adds a score, have it add it to the array and save it to NSUserDefaults.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Reply

Bookmarks

Tags
data, plist, save, scores

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 393
13 members and 380 guests
7twenty7, AppsBlogger, Creativ, David-T, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, Sami Gh, teebee74, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:49 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0