4

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?

Dan Waterbly
  • 850
  • 7
  • 15

1 Answers1

14

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:

Community
  • 1
  • 1
albertamg
  • 28,492
  • 6
  • 64
  • 71
  • 2
    You might want to mention that you copy-pasted a large chunk of the above from http://developer.apple.com/library/ios/#documentation/general/Conceptual/DevPedia-CocoaCore/RootClass.html :-) – John Parker Jun 01 '11 at 15:26
  • @middaparka Thank you for the link! I added it to the answer. I read this info inside a pop-up in the very beginning of the overview section of NSObject Class Reference, when I clicked "root class" and then "More...", so I was still looking for the link when you commented. Thank you! – albertamg Jun 01 '11 at 15:31
  • 2
    As an aside; if you anyone is thinking of making their own root class.... don't. You'll end up having to rewrite most of NSObject (including some rather gnarly non-obvious bits like KVO and KVC) if you want it to inter-operate with Foundation provided classes (or above). – bbum Jun 01 '11 at 15:37
  • Never in Cocoa Touch applications? I used it :( – Dustin Howett Jul 21 '11 at 04:29