Inheritance and Protocols

One of the important concepts of object-oriented programming is inheritance, which allows for creating simpler and more efficient code by allowing one class to inherit all the properties of another class. This gives the benefit of polymorphism, where a variable can be declared to hold a particular type in the code, but at runtime, any object declared of that class or any of its subclasses can be assigned to the variable.

Inheritance in Objective-C works exactly like it does in Java and C#. Only the syntax is slightly different. To specify inheritance, you add a colon and the super class name to the @interface line in the .h file. For instance, the Book class you created earlier could form the basis for a PhotoBook class, ...

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android 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.