Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much of the "Objective-C" I'm learning is universal Objective-C, and not Apple's frameworks?

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! =)

like image 255
Chris Cooper Avatar asked Jun 05 '10 22:06

Chris Cooper


People also ask

Is Objective-C still supported by Apple?

Most of the core iOS and MacOs software is still written in Objective-C, though Apple is pushing for new updates to be written in Swift.

Is Objective-C still used 2022?

Furthermore, Objective-C is a piece of art, creators packed genius solutions and were constantly improving it, so us developers were able to use it at our advantage. There are a lot of indicators telling us there's still a ton of legacy Objective-C code, both from Apple and from other developers, that's still in use.

What is Objective-C in iOS?

Objective-C is the primary programming language you use when writing software for OS X and iOS. It's a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime.

Does Apple use C language?

The C programming language has been around since the 1970s, but it has never gone out of style, and learning C is one of the best computer skills you can acquire. Mac OS X comes with C built into it, and Apple has used C while making every aspect of OS X and iOS.


2 Answers

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.

like image 100
Yann Ramin Avatar answered Nov 15 '22 12:11

Yann Ramin


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];

EDIT

Given that you have an objective-c compiler such as GCC you still need an Objective-c runtime in order to make the above stuff work. e.g. [anObject aMessage] is actually compiled to

objc_msgSend( anObject, @selector(aMessage));

...therefore the symbol objc_msgSend is one of several that must exist at runtime. In theory this could be provided by a compiler intrinsic but in practice you are probably going to link to an Objective-c runtime library - a quick search of my hard drive shows i have three installed:- Apple's, GNUStep, and Cocotron - there are more but Apple's (open source) is without doubt the most important and influential.

With an Objective-c compiler and runtime - but without any Apple Objective-c frameworks (NSObject, etc.) - you have a fabulous and very useful C-with-Classses that is much simpler (where simpler means 'better for me') than C++.

like image 34
hooleyhoop Avatar answered Nov 15 '22 12:11

hooleyhoop