Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8822719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:10:28+00:00 2026-06-14T06:10:28+00:00

I’m new and stuck any help would be great! I am using Xcode to

  • 0

I’m new and stuck any help would be great! I am using Xcode to build my app.

I have an IBAction “button pressed”, this generates random numbers, then I have a bunch of if statements. Ultimately if things match up my long long variable “coins” has a numeric value. Right now I just change that value as in coins = coins + 10 and then display it in a UILabel. I now need to store that value, after all the calculations, whenever the user presses the button. So that their total of “coins” is being added to or subtracted from. Additionally I will want to add and In App Purchase that ads to the “coins” variable. So I know I need a way to store the value, even when the app is closed and re-opened.

Is there a way to use NSUserDefaults to store that value, either within the original IBAction buttonPressed? Also Or any help at all or suggestions would be great! Thanks and sorry if this sounds lame, but I’m on my first app 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:10:29+00:00Added an answer on June 14, 2026 at 6:10 am

    To store a number in NSUserDefaults:

    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedLongLong:coins] forKey:@"coins"];
    

    To retrieve from NSUserDefaults and store it into coins:

    coins = [[[NSUserDefaults standardUserDefaults] objectForKey:@"coins"] unsignedLongLongValue];
    

    This is assuming you’ve declared coins as being an unsigned long long, and not a signed one. Also, there are convenience methods for storing NSIntegers if you want to go through those.

    EDIT: Just realized you want to have IAPs, should’ve read more carefully. I recommend against storing anything of value (passwords, usernames, purchasable currency, highscores that can be submitted to an online leaderboard, etc) in NSUserDefaults. It’s stored as a simple .plist (XML) which could be edited relatively easily as far as I understand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.