Re: Yet another stupid newbie's question
Re: Yet another stupid newbie's question
- Subject: Re: Yet another stupid newbie's question
- From: Guillaume Borios <email@hidden>
- Date: Tue, 28 Aug 2001 13:17:01 +0200
Le mardi 28 ao{t 2001, ` 12:16 PM, email@hidden a icrit :
Hello list,
It's again around type conflicts, pointers and stuff... Probably I'm
trying
to mix objects and c-style vars in a wrong way
I've done an array containing integers.
it's filled by:
...
[myArray addObject:[NSNumber numberWithInt:10]];
[myArray addObject:[NSNumber numberWithInt:123]];
[myArray addObject:[NSNumber numberWithInt:4]];
[myArray addObject:[NSNumber numberWithInt:56]];
...
A simple
for (index=0;index<max;index++) {
NSLog (@"debug --> %@", [myArray objectAtIndex:index]);
}
tells me that all values are stored fine.
Well, my question is, how can I do some mathematics (additions,
comparing in
size) with this values???
int value=[myArray objectAtIndex:0] makes the compiler scream:
"assignment makes integer from pointer without a cast"... :-(
[myArray objectAtIndex:0] returns a pointer (type id) to the NSNumber
Object stored at index 0. To get the value of the NSNumber object try :
int value = [[myArray objectAtIndex:0] intValue];
Refer to the cocoa foundation frameworks docs for more details (NSNumber
and NSArray sections)...
Guillaume