Separate Interface and Implementation Files

It’s time to get used to putting your class declarations and definitions in separate files.

If you’re using Xcode, start a new project called FractionTest. Type the following program into the file main.m.

Program 7.1 Main Test Program: main.m

#import "Fraction.h"int main (int argc, char * argv[]){   @autoreleasepool {      Fraction  *myFraction = [[Fraction alloc] init];      // set fraction to 1/3      [myFraction setNumerator: 1];      [myFraction setDenominator: 3];      // display the fraction      NSLog (@"The value of myFraction is:");      [myFraction print];   }   return 0;}

Note that this file does not include the definition of the Fraction class. However, it ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.