
-----------------------------------
wtd
Sun Feb 22, 2004 12:12 am

[Obj-C] Helpful Links
-----------------------------------
The Objective-C Foundation Class are a library of classes and protocols devoid of dependence on either Apple's Cocoa API, or the GNUStep libaries.

http://ofc.sunsite.dk/

The Objective-C FAQ is always a good reference.

ftp://rtfm.mit.edu/pub/faqs/computer-lang/Objective-C/faq

-----------------------------------
rizzix
Sun Feb 22, 2004 8:21 am


-----------------------------------
nice.

got any programs you created in obj-c that you can show us?

-----------------------------------
wtd
Mon Feb 23, 2004 12:42 am


-----------------------------------
Unfortunately no.  My recent work has been in C++ and Ruby primarily.

-----------------------------------
wtd
Tue Feb 24, 2004 7:15 pm


-----------------------------------
Saw a thread about a Fraction class in another forum here and thought it might make an educational example.

// import the base class
#import 



@interface IntPair : Object
{
	@private 
	int first, second;
}
- initWithFirst: (int) f andSecond: (int) s;
- (int) greater;
- (int) lesser;
- (bool) bothDivisibleBy: (int) t;
- (int) gcd;
- (int) first;
- (int) second;
- (void) first: (int) newValue;
- (void) second: (int) newValue;
- (void) swap;
@end



@interface Fraction : IntPair
- initWithNumerator: (int) initNum andDenominator: (int) initDenom;
- clone;
- (void) invert;
- (void) simplify;
- (int) numerator;
- (int) denominator;
- (void) numerator: (int) newValue;
- (void) denominator: (int) newValue;
- (void) simplifySigns;
- (void) multiplyBothBy: (int) multiplier;
- (int) wholeNumberValue;
- (Fraction *) remainder;
- (Fraction *) multiplyByFraction: (Fraction *) other;
- (Fraction *) multiplyByInt: (int) other;
@end




int main(int argc, char * argv[])
{
	Fraction * f = [[Fraction alloc] initWithNumerator: 2 andDenominator: 3];
	Fraction * s = [[Fraction alloc] initWithNumerator: 3 andDenominator: 4];
	Fraction * r = [f multiplyByFraction: s];
}




@implementation IntPair
- initWithFirst: (int) f andSecond: (int) s
{
	[super init];
	[self first: f];
	[self second: s];
	return self;
}

- (int) greater
{
	if ([self first] >= [self second])
		return [self first];
	else
		return [self second];
}

- (int) lesser
{
	if ([self first] 