Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default base class for objective c classes

The answer to this question may be obvious but I need to ask it to be certain:

Do all objective c classes share a common default base class when a base class is not explicity defined in the class definition?

like image 823
Dan Waterbly Avatar asked Dec 10 '22 08:12

Dan Waterbly


1 Answers

No, if you do not explicitly define a super class in the class definition you are creating a root class.

From Cocoa Core Competencies:

A root class inherits from no other class and defines an interface and behavior common to all objects in the hierarchy below it. All objects in that hierarchy ultimately inherit from the root class. A root class is sometimes referred to as a base class.

The root class of all Objective-C classes is NSObject, which is part of the Foundation framework. All objects in a Cocoa or Cocoa Touch application ultimately inherit from NSObject. This class is the primary access point whereby other classes interact with the Objective-C runtime. It also declares the fundamental object interface and implements basic object behavior, including introspection, memory management, and method invocation. Cocoa and Cocoa Touch objects derive the ability to behave as objects in large part from the root class.

enter image description here

The Foundation framework defines another root class, NSProxy, but this class is rarely used in Cocoa applications and never in Cocoa Touch applications.

See also:

  • Why subclass NSObject?

  • What use cases are there for defining a new root class?

like image 166
albertamg Avatar answered Dec 28 '22 02:12

albertamg