views:

199

answers:

4

This question is related to one of my others about C: What can you do in C without “std” includes? Are they part of “C,” or just libraries?

I've become curious lately as to what is really contained the the core Objective-C language, and what parts of the Objective-C I've done for iPhone/OS X development is specific to Apple platforms.

I know that things like syntax are the same, but for instance, is NSObject and its torrent of NS-subclasses actually part of "standard" Objective-C? Could I use them in, say, Windows?

What parts are universal for the most part, and what parts would I only find on an Apple platform?

If you want, giving an example of Objective-C used elsewhere as an example of what is more "universal" would help me as well.

Thanks! =)

+10  A: 

There are only two current implementations of the core Objective-C libraries, previously known as the NextStep (hence NS prefixes) and OPENSTEP: GNUStep and Apple's OS X. On Linux, if you maintain compatibility with the OPENSTEP specification, GNUStep works very well. However, the specification is ancient, and modern code for OS X will likely not work correctly (especially in the UI area). The situation on Windows is even worse.

You can use the Objective-C language anywhere GCC supports the build target. The "NS" classes are not part of the language proper.

If you're trying to maintain compatibility across platforms in your code base, stick to C or C++, only move UI specific behavior to Objective-C.

Yann Ramin
Much better answer than mine, so I deleted it.
Omnifarious
+2  A: 

None of the class library is part of the language itself. If you want to see the core Objective-C types, look in include/objc. The core language itself, without any added library, is really scant and not particularly useful.

In practice, however, Objective-C is just about never used outside of the context of an OpenStep framework like Cocoa or GNUstep. So you could view that as the de facto standard library, in which case Foundation is almost universal. (Not 100% of Foundation is that way, but the majority is.)

Chuck
+2  A: 

You can a lot on Windows using Cocotron, which is a free implementation of Apple's frameworks. It's not complete, and you may run into bugs, but if you're lucky, you can compile your Xcode project as a Windows app without too many changes.

Zydeco
+1  A: 

Objective-c is C plus these keywords

@interface, @implementation, @protocol, @end, @private, @protected, @public, @try, @throw, @catch, @finally, @class, @selector, @encode, @"string", @synchronized, @property, @synthesized

Plus the message sending syntax [anObject aMessage];

NSObject is not needed for fabulous and very useful C-with-Classses that is much simpler (where simpler means better for me) than C++.

mustISignUp