它在我使用时有效NSLog
,但不是printf
。我想使用printf
,因为这样所有元素setA
都将显示在一行中。
#import <Foundation/Foundation.h>
#define INTOBJ(v) [NSNumber numberWithInteger: v]
@interface NSSet (Printing)
-(void) print;
@end
@implementation NSSet (Printing)
-(void) print {
for (NSNumber *element in self)
printf("%li", (long) [element integerValue]);
}
@end
int main (int argc, char *argv[]) {
@autoreleasepool {
NSMutableSet *setA = [NSMutableSet setWithObjects:INTOBJ(3), INTOBJ(10), INTOBJ(1), INTOBJ(5), nil];
[setA print];
}
return 0;
}