How to Implement Classes in iOS App Development - dummies

How to Implement Classes in iOS App Development

By Rajiv Ramnath

As may be obvious, the implementation of a class for iOS apps consists of the implementation of its methods. The following listing gives you a good idea about what a method implementation is and what a class’s overall implementation specification looks like. Implement the class by using an implementation specification bracketed by the @implementation directive, as shown here:

@implementation <Class Name>;
…
 <Implementation of methods and other code>
…
–d

This is the implementation for the StackOfInteger class:

@implementation StackOfInteger;
- (id) init{
 self = [super init];
 last = -1;
 elements = [[NSMutableArray alloc] init];
 return self;
}
- (BOOL) isEmpty{
 return (last == -1);
}
- (void) push: (int) intValue{
 NSNumber* intObject = [NSNumber numberWithInt:intValue];
 [elements addObject:intObject];
 last++;
}
- (void) push2: (int) intValue1 another:(int) intValue2 {
 NSNumber* intObject = [NSNumber numberWithInt:intValue1];
 [elements addObject:intObject];
 intObject = [NSNumber numberWithInt:intValue2];
 [elements addObject:intObject];
 last+=2;
}
- (int) pop{
 NSNumber* element = (NSNumber *) [elements objectAtIndex:last];
 last--;
 int intValue = [element intValue];
 [elements removeLastObject];
 return intValue;
}
–d