An Objective-C Class for Working with Fractions
Now it’s time to define an actual class in Objective-C and learn how to work with instances of the class.
Once again, you’ll learn procedure first. As a result, the actual program examples might not seem very practical. We get into more practical stuff later.
Suppose that you need to write a program to work with fractions. Maybe you need to deal with adding, subtracting, multiplying, and so on. If you didn’t know about classes, you might start with a simple program that looked like this.
// Simple program to work with fractions#import <Foundation/Foundation.h>int main (int argc, char * argv[]){ @autoreleasepool { int numerator = 1; int denominator = 3; NSLog (@"The ...
Get Programming in Objective-C, Fifth 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.