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

  • Home
  • SEARCH
  • 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 8271223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:47:13+00:00 2026-06-08T06:47:13+00:00

I have done this code to store score. But this is giving me the

  • 0

I have done this code to store score.

But this is giving me the last added score only, not storing data every time on new index.

-(IBAction)btnSaveScore:(id)sender
{
    if(!dictWinData)
        dictWinData = [[NSMutableDictionary alloc] init];

    array = [NSMutableArray arrayWithObjects:txt_EnterName.text,
                                             [NSString stringWithFormat:@"%i",iTap], nil];

    int increment = 0;

    NSLog(@"array data is:--> %@",array);

    for (int intWinData = 1; intWinData < [array count]; intWinData++)
    {
        [dictWinData setObject:array forKey:[NSString stringWithFormat:@"NameScore%d",increment]];
        increment++;
    }
}

If any mistake is there in my code then please let me guide for this.

Is there anyother way to store the data..?

Is NSUserDefaults helpful to store & display data…?

How to use NSUserDefaults to store & retrive data.

Thanks.

  • 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-08T06:47:14+00:00Added an answer on June 8, 2026 at 6:47 am

    The issue is with this line:

    int increment = 0;
    

    Every time you press the save button the increment will be initialized to zero and hence every time the value is added to dictionary for same key NameScore0. Hence it will over write the existing dictionary value.

    You need to make the increment as static like static int increment = 0; or make it as a global variable, it will solve the issue.

    -(IBAction)btnSaveScore:(id)sender
    {
        if(!dictWinData)
            dictWinData = [[NSMutableDictionary alloc] init];
    
        array = [NSMutableArray arrayWithObjects:txt_EnterName.text,
                                                 [NSString stringWithFormat:@"%i",iTap], nil];
    
        static int increment = 0;
    
        for (int intWinData = 1; intWinData < [array count]; intWinData++)
        {
            [dictWinData setObject:array forKey:[NSString stringWithFormat:@"NameScore%d",increment]];
            increment++;
        }
    }
    

    NSUserDefaults is used for displaying the application setting in the ios device’s settings pane. Don’t save your application data there.
    Instead of NSUserDefaults you can use plist to store data.

    Please check the link

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

Sidebar

Related Questions

i have done some code in jquery but where i commented in this bellow
Quick question, What have I done wrong here. The purpose of this code is
I have this jQuery code: $(document).ready(function() { $.ajax({ url: pages/+page+.php, cache: false }).done(function( html
I have found myself doing this in my code to 'cache' the work done
I have done this without much effort on T-SQL, but I want to implement
I have done this before but I forgot where in my app I have
It's the first time I have done anything like this but wondered what the
I know that this is not the first thread on this topic,but I have
I have this bit of code which I am not sure if it is
I have done this operation millions of times, just using the + operator! I

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.