Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Oneill

macrumors newbie
Original poster
Nov 10, 2012
13
0
- I want to add objects to the property list I created which in my case called (highscoreArray) but what the problem I'm facing is that it adds the object then release it, in other words the next time I check the 'count' input it keeps showing only the number 1(see the Check method below) .
Code:
// Lazy Instantiation.
-(NSMutableArray *)highscoreArray
{
    if(!_highscoreArray) _highscoreArray=[[NSMutableArray alloc]init];
    return _highscoreArray;
}

-(void)Arraywithscores:(int)score
{  NSNumber *point = [NSNumber numberWithInt:score];
    [self.highscoreArray addObject:point];
    [self Check:self.highscoreArray];
}

-(void)Check:(NSMutableArray *)highscoreArray
{
    NSLog(@"The number is %i",[highscoreArray count]);
}

- Any solutions please ?
 
You're not sharing enough with us... I don't see how your Check: or Arraywithscores: methods could be called multiple times.

On a side note, these method names are horrid:
1 - Don't capitalize the first letter of method names.
2 - Do capitalize other letters to signal where new words start.
3 - Don't pluralize the last word of a method name if it only takes a single, non-collection argument.

Your methods should be called check: and arrayWithScore:
 
You're not sharing enough with us... I don't see how your Check: or Arraywithscores: methods could be called multiple times.

On a side note, these method names are horrid:
1 - Don't capitalize the first letter of method names.
2 - Do capitalize other letters to signal where new words start.
3 - Don't pluralize the last word of a method name if it only takes a single, non-collection argument.
Coding Guidelines for Cocoa.

It's mainly about naming.
 
You're not sharing enough with us... I don't see how your Check: or Arraywithscores: methods could be called multiple times.

On a side note, these method names are horrid:
1 - Don't capitalize the first letter of method names.
2 - Do capitalize other letters to signal where new words start.
3 - Don't pluralize the last word of a method name if it only takes a single, non-collection argument.

Your methods should be called check: and arrayWithScore:

Thank you for the note appreciate it though this is a quick unorganized code.
More details about the project:
-It is a quiz game a right question increase the score by 10, so basically what I have is a score label' obviously for displaying the score via the score property' and a timer once time is up the score must be added to the array.
thats all !
Input:
2013-10-02 21:05:07.246 Project[989:c09] The number is 1
The old scores are all gone though as you can see.
 
- Any solutions please ?

Post your @interface for the class, showing the instance variable and the property declarations.

Also post the init method for the class, and any/all synthesized property accessors.

----------

Thank you for the note appreciate it though this is a quick unorganized code.

Organize it, then post it.

What you've posted is insufficient to diagnose anything. The first rule of getting advice about code is "Post your code". Not just the code you think is relevant, but all of it.

Here's why you post all your code. If you don't understand everything that's happening, then you can't accurately decide what's relevant code and what isn't. A frequent result is that you leave out something that's actually important, but because no one sees it, and you didn't say that code exists, the error-causing code never gets seen.

Read this and follow its guidelines:
http://www.mikeash.com/getting_answers.html
 
- I want to add objects to the property list I created which in my case called (highscoreArray) but what the problem I'm facing is that it adds the object then release it, in other words the next time I check the 'count' input it keeps showing only the number 1(see the Check method below) .
Code:
// Lazy Instantiation.
-(NSMutableArray *)highscoreArray
{
    if(!_highscoreArray) _highscoreArray=[[NSMutableArray alloc]init];
    return _highscoreArray;
}

-(void)Arraywithscores:(int)score
{  NSNumber *point = [NSNumber numberWithInt:score];
    [self.highscoreArray addObject:point];
    [self Check:self.highscoreArray];
}

-(void)Check:(NSMutableArray *)highscoreArray
{
    NSLog(@"The number is %i",[highscoreArray count]);
}

- Any solutions please ?

don't know if you figured this out yet, but just make sure you have a property for your array

Code:
 @property (strong, nonatomic) NSMutableArray *highscoreArray;

the formatting of your code could use some work, but the functionality is there. just make sure you have a reference to the array. anything else inside the array will have a strong pointer to it by default.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.