views:

318

answers:

3

Hello,

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.

+4  A: 

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
I don't use Cocoa, because i'm on Linux, then i use GNUstep with gcc. ;)
Nathan Campos
+3  A: 

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
I going to take a look at this reference. Thanks.
Nathan Campos
Glad to have helped!
ennuikiller
+4  A: 

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
Then i can import NSObject and i will not have any problems with the syntax?
Nathan Campos
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