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

henkhenk

macrumors newbie
Original poster
Nov 2, 2009
10
0
hi all:

I want to keep track of some numbers. for this purpose I will need to use an array of numbers:

should I create it and use it the following way or there is an easy way?

NSMutablearray *array1;

[array1 addObject:[NSString stringWithFormat:mad:"%d", count]];
 
If they are really numbers why not use NSNumber instead of NSString?

Or, if you know the size in advance, why not just use a C array?

hi robbieduncan tanks for the replay.

I dont know the size in advance. and if I will add the number to the array like this way:
[array1 addObject:[NSString stringWithFormat:mad:"%d", count]];

how I can read it back and assign it to an NSIntiger or int? (like if I want to select one value from the array by an objectIndex.)

tanks
henk
 
As per my above suggestion: don't store it like that. If it's a number don't convert it to a string. You are just asking for pain. Store it as a NSNumber.
 
As per my above suggestion: don't store it like that. If it's a number don't convert it to a string. You are just asking for pain. Store it as a NSNumber.

I had some problem with NSNumber.

ok I will try it.

tanks
 
I had some problem with NSNumber.

ok I will try it.

tanks
problem solved:

to ad an int to NSMutableArray:
int count;
NSMutableArray *array1;
NSNumber *mynum =[NSNumber numberWithInteger:count];
[array1 addObject:mynum];


to covert NSNumber in NSMutableArray to int:
int x = [[array1 objectAtIndex:indeX] intValue];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.