Reputation: 1877
I declared a nsmutablearray and assign some object but when retrieving object it gives memory location.Here is the code.
NSMutableArray *arrCondiNum = [[NSMutableArray alloc] init];
[arrCondiNum addObject:@"2"];
[arrCondiNum addObject:@"4"];
[arrCondiNum addObject:@"6"];
[arrCondiNum addObject:@"8"];
for(int i = 0;i<[arrCondiNum count];i++){
NSLog(@"Array number %d",[arrCondiNum objectAtIndex:i]);
}
Output it gives
Array number 20820
Array number 20836
Array number 20852
Array number 20868
Upvotes: 1
Views: 650
Reputation: 67
just write like this.. NSLog(@"Array number %@",[arrCondiNum objectAtIndex:i]); u have to print some text..so
Upvotes: 0
Reputation: 99092
Note that in case you want an array of numbers, use NSNumber
instead:
[array addObject:[NSNumber numberWithInt:1]];
You still have to use the %@
format specifier though (as NSNumber
is a class-type) or retrieve the integer value using -intValue
.
Upvotes: 2
Reputation: 7427
You add string in your array, then to display it, you have to use %@:
NSLog(@"Array number %@",[arrCondiNum objectAtIndex:i]);
In your code (%d), you display the address of the object.
%@ will display the description of the ObjC object (return of -descriptionWithLocale:
or -description
)
Upvotes: 3
Reputation: 8990
Try [[arrCondiNum objectAtIndex:i] floatValue]
instead. NSArrays are keeping objects (pointers to objects to be more precise), not values. So the array will return the string object you created earlier. By sending this object the "floatValue" message, it will return its content represented as float value. You could use intValue as well to receive an integer.
Upvotes: 0