本帖最后由 董月峰 于 2014-4-13 15:29 编辑
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
// NSNumber *numOc = [NSNumber numberWithInt:-28]; // // NSLog(@"%@", numOc);
NSMutableArray *array = [NSMutableArray arrayWithObjects: @1, @9, nil]; NSNumber *numOc = [NSNumber numberWithInt:-28]; [array addObject:numOc];
NSArray *sortedArray = [array sortedArrayUsingSelector: @selector( compare: )];
NSLog(@"%@", sortedArray);
return 0; } 这样输出的结果是: ( "-28", 1, 9
) #import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
NSNumber *numOc = [NSNumber numberWithInt:-28];
NSLog(@"%@", numOc);
// NSMutableArray *array = [NSMutableArray arrayWithObjects: @1, @9, nil]; // NSNumber *numOc = [NSNumber numberWithInt:-28]; // [array addObject:numOc]; // // NSArray *sortedArray = [array sortedArrayUsingSelector: @selector( compare: )]; // // NSLog(@"%@", sortedArray);
return 0; }
这样输出的结果是:-28
疑惑:请问为什么同一个NSNumber型的负整数单独打印和在数组中打印不同? |