9

I'm learning Objective-C and as I can see, in some tutorials they use Object(imported from objc/Object.h) and in others i see the use of NSObject(imported from Foundation/NSObject.h), but what are the main differences between they?

Regards.

Nathan Campos
  • 28,769
  • 59
  • 194
  • 300

3 Answers3

6

Objective-C is just the language.

The Cocoa frameworks use the NSObject base class as the root class for the hierarchy. Other implementations use their own root classes, in your case the Object class.

Abizern
  • 146,289
  • 39
  • 203
  • 257
6

You should ignore Object.

Objective-C allows multiple root classes. Object is a root class that predates NSObject. It's never something you would want to go use. It's only relevant when something somehow already interacts with Object, so you have to deal with it. This is very rare.

Object doesn't implement -retain and -release, for example.

Ken
  • 12,933
  • 4
  • 29
  • 32
  • Then i can import NSObject and i will not have any problems with the syntax? – Nathan Campos Oct 19 '09 at 19:49
  • Not quite sure what you mean, but probably yes. You might also want to ignore the tutorial you linked that uses Object. I think you'll have a hard time finding any others that refer to it. – Ken Oct 20 '09 at 01:36
4

NSObject contains all the infrastructure of the Cocoa framework. In other words it conforms to several protocols that Object does not and will respond to certain methods that Object will not. Specifically see NSObject Class Reference and

ennuikiller
  • 46,381
  • 14
  • 112
  • 137