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 8951211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:36:41+00:00 2026-06-15T13:36:41+00:00

Suppose I have a @property that is an NSMutablearray that is to contain scores

  • 0

Suppose I have a @property that is an NSMutablearray that is to contain scores used by four objects. They will be initialized as zero and then updated during viewDidLoad and throughout operation of the app.

For some reason, I can’t wrap my mind around what needs to be done, particularly at the declaration and initialization steps.

I believe this can be a private property.

@property (strong, nonatomic) NSMutableArray *scores;

@synthesize scores = _scores;

Then in viewDidLoad I try something like this but get an error. I just need help with syntax, I think. Or I’m missing something very basic.

self.scores = [[NSMutableArray alloc] initWithObjects:@0,@0,@0,@0,nil];

Is that an appropriate way to initialize it? Then how do I add (NSNumber *)updateValue to, say, the nth value?

Edit: I think I figured it out.

-(void)updateScoreForBase:(int)baseIndex byIncrement:(int)scoreAdjustmentAmount
{
    int previousValue = [[self.scores objectAtIndex:baseIndex] intValue];
    int updatedValue = previousValue + scoreAdjustmentAmount;
    [_scores replaceObjectAtIndex:baseIndex withObject:[NSNumber numberWithInt:updatedValue]];
}

Is there a better way of doing this?

  • 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-15T13:36:43+00:00Added an answer on June 15, 2026 at 1:36 pm

    You are initializing in viewDidLoad, However you should do it in init.

    These both are similar, and perfectly valid.

    _scores = [[NSMutableArray alloc] initWithObjects:@0,@0,@0,@0,nil]; 
    

    or,

    self.scores=[[NSMutableArray alloc]initWithObjects:@0,@0,@0, nil];
    

    Your last question… Then how do I add (NSNumber *)updateValue to, say, the nth value?
    If you addObject: it will be added at last. You need to insertObject:atIndex: in your required index, and all following objects will shift to next indices.

     NSInteger nthValue=12;
    [_scores insertObject:updateValue atIndex:nthValue];
    

    EDIT:

    After your edit,

    NSInteger previousValue = [[_scores objectAtIndex:baseIndex] integerValue];
    NSInteger updatedValue = previousValue + scoreAdjustmentAmount;
    [_scores replaceObjectAtIndex:baseIndex withObject:[NSNumber numberWithInt:updatedValue]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that I have two objects with the same property name that I am
Suppose I have a Python class that I want to add an extra property
Let's suppose I have an instance anInstance of some class that has a property
Suppose I have a div in my page, that doesn't have a width property
Suppose I have a view model with a property that looks something like this:
Suppose I have a list of objects called TheListOfMyObjects . In that list, there's
Suppose you have class B with lazily loaded property c . And that this
Suppose that I have a property containing c:\workdir\project\wonder\subproj\..\..\common and I want to reduce/simplify it
Suppose I have a UISlider interface element that I connected to a property in
Suppose I have a model Stock that has several StockPartition (its a property called

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.