Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
January 23, 2018, 08:57:31 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: exercise 15-10  (Read 1378 times)
mdziedzic
Newbie
*
Posts: 41



WWW
« on: December 10, 2009, 12:57:20 PM »

Code: (Objective-C)
#import <Foundation/Foundation.h>

#define INT(x) [NSNumber numberWithInteger: x]

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSArray *numbers = [NSArray arrayWithObjects:
INT(42), INT(111), INT(3), INT(55), INT(99),
INT(77), INT(99), INT(68), INT(1), INT(5),
INT(99), INT(100), INT(100), INT(25), INT(86),
INT(42), INT(-5), INT(-5), INT(42), INT(42), nil];

NSCountedSet *cSet = [[NSCountedSet alloc] initWithArray: numbers];

for (NSNumber *theNumber in cSet)
NSLog(@"%3i: %i", [theNumber intValue], [cSet countForObject: theNumber]);

[cSet release];
   
[pool drain];
    return 0;
}




111: 1
 42: 4
 86: 1
 55: 1
 99: 3
  5: 1
  3: 1
  1: 1
 68: 1
 -5: 2
100: 2
 77: 1
 25: 1


Logged
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #1 on: December 11, 2009, 10:58:57 AM »

Hi,

You should use the integerValue method to retrieve a number created with numberWithInteger:.

Cheers,

Steve Kochan
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 classroomM.com. All rights reserved.