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

blue-lion

macrumors member
Original poster
Jan 26, 2010
50
0
hello again, i am experimenting with the addobject method ,and previously i have managed to interrogate the contains of the nsmutablearray within the debugger, but this time although no error or warning message is being displayed i can't seem to do it. The array variable is there, but shows no contents?

the array is declared as part of a class in the usual way

with
Code:
NSMutableArray *scoreLog;

@property(nonatomic,strong) NSMutableArray *scoreLog;

in the header



and in the implementation file

@synthesize scoreLog;



later in the implementation file , i have the following line

Code:
[scoreLog addObject:[NSNumber numberWithInt:10]];

just after this command i set up a break point and look at the scoreLog
but there nothing inside it?

any ideas?
 
Last edited by a moderator:

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
No where are you actually creating an NSMutableArray instance and assigning it to the property. All you have declared is a variable to store the instance and that it's a property with synthesized accessors. This does not magically create an array instance assigned to that property.
 

blue-lion

macrumors member
Original poster
Jan 26, 2010
50
0
viewing arrays

sorry , I'm still a relative newbie…


whats the difference between creating an instance, and declaring a variable to store an instance?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
sorry , I'm still a relative newbie…


whats the difference between creating an instance, and declaring a variable to store an instance?

If you don't know that the best thing to do is stop writing code and go and read up on the very basics of programming. Essentially what is the difference between having a space to park a car and actually having a car?
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
whats the difference between creating an instance, and declaring a variable to store an instance?

Declaring a variable:
Code:
NSMutableArray *scoreLog;

Creating an instance (and calling init on it since those tend to go together...)
Code:
[[NSMutableArray alloc] init];

Doing both in one line:
Code:
NSMutableArray *scoreLog = [[NSMutableArray alloc] init];

Methods that create an instance are class methods that return an id or pointer to the instance that was created.

Class methods are the ones prefixed with a + (rather than a - ) in their declaration.
 

blue-lion

macrumors member
Original poster
Jan 26, 2010
50
0
problems viewing contents of array

sorry, one further thought...

i assume i don't have to alloc-init on instance variables?, only arbitrary variables not part of any class?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.