Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference Between Object And NSObject

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.

like image 279
Nathan Campos Avatar asked Oct 19 '09 17:10

Nathan Campos


3 Answers

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.

like image 107
Ken Avatar answered Sep 19 '22 09:09

Ken


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.

like image 41
Abizern Avatar answered Sep 23 '22 09:09

Abizern


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

like image 41
ennuikiller Avatar answered Sep 22 '22 09:09

ennuikiller