1

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

4 Answers 4

3

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)

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

0

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.

1 Comment

For %d the float value is not useful, it should definitely be -intValue.
0

just write like this.. NSLog(@"Array number %@",[arrCondiNum objectAtIndex:i]); u have to print some text..so

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.