Objective c key path operators @avg,@max .....
Posted
by davide
on Stack Overflow
See other posts from Stack Overflow
or by davide
Published on 2010-04-03T22:53:37Z
Indexed on
2010/04/03
23:03 UTC
Read the original article
Hit count: 295
objective-c
arr = [[NSMutableArray alloc]init];
[arr addObject:[NSNumber numberWithInt:4]];
[arr addObject:[NSNumber numberWithInt:45]];
[arr addObject:[NSNumber numberWithInt:23]];
[arr addObject:[NSNumber numberWithInt:12]];
NSLog(@"The avg = %@", [arr valueForKeyPath:@"@avg.intValue"]);
This code works fine, but why? valueForKeyPath:@"@avg.intValue"
is requesting (int) from each NSNumber, but we are outputting a %@ string in the log. If i try to output a decimal %d i get a number that possibly is a pointer to something. Can somebody explain why the integers become NSNumbers when i call the @avg operator?
© Stack Overflow or respective owner