26

I'm a C and C++ programmer trying to get started with Objective-C. I'm really bewildered, though, by the apparent total absence of a standards document for the language and standard library. I can understand that there's no ISO standard, but is there no reference document at all? And how is it that nobody seems very concerned about this state of affairs? (Admittedly, it's hard to Google for such a thing, because "reference", "document", and "standard" are all overloaded terms. So it's possible that I've just missed something critical.)

This question gets close to asking the same thing: Where can i find a document explaining how Objective-C is implemented and the only answer provided was "read this source code published by Apple which is pretty close to what their implementation did a few years ago, maybe".

This page: http://clang.llvm.org/docs/ObjectiveCLiterals.html includes a snippet of a formal grammar for Objective-C, but ironically it's in the context of describing a feature that Clang just went off and added on their own and that nobody else supports. There's another grammar here: http://www.omnigroup.com/mailman/archive/macosx-dev/2001-March/022979.html but it's more than 10 years old.

To narrow the question down to the barest minimum: I'd like to know what methods are guaranteed to be provided by "Object", and what the behavior of each method is. For other languages, this type of information is usually provided by something like this: http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html

Community
  • 1
  • 1
Quuxplusone
  • 23,928
  • 8
  • 94
  • 159
  • 1
    +1, good question and well researched. do take care of using the proper tags from next time, to ensure better visibility, for [the right people](http://stackoverflow.com/tags/objective-c/topusers). also read the tag wikis before tagging, and make sure their meanings are what you intend them to be. – bool.dev Jun 12 '12 at 03:36
  • Good question indeed. NSObject ([iOS](https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html) / [OS X](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html)) is a root class btw. – Filip Radelic Jun 12 '12 at 03:47
  • C and C++ standardize their libraries. Note that cocoa is not standardized so NSObject is entirely whatever Apple decides. There are alternative libraries to cocoa like GnuStep and objfw. It is strange that there is no language spec however. Especially since Objective-C is included in GCC, independent of Apple. – Justin Meiners Feb 13 '19 at 01:19

3 Answers3

15

Unfortunately there is no Standard for ObjC as there is for C++ or C. Apple being the main user and driver behind the language, their compiler implementation (the ObjC bits of Clang) is the de facto Standard. Their old document (broken link) "The Objective-C Programming Language" was about as close as you got to a prose version, and it was nowhere near the precision of either of those other languages' Standards (and it tends to lag behind the compiler).

It may still be floating around on the web somewhere, but it is no longer up-to-date. "Programming with Objective-C" seems to be their intended replacement (but again, it's nothing like a standard).

Regarding your comment (10k link only) under Tim's deleted answer, the Cocoa root class is NSObject, and its interface is documented, but its source is not available. Note that the NSObject protocol is also an extremely important part of a Cocoa object's functionality. Apple's runtime is open-source,* and has a root class called Object, I assume for purposes of demonstration. It's not used in Cocoa programming.

You already know about all of this, of course. The direct answer to your question is, "there isn't one". Most of the syntax is the same as C, though, as bbum points out: Authoritative description of ObjectiveC string literals? (yes, I copy-pasted my comment from there into the beginning of this answer).


*Note that contrary to what you say in your question, this is the actual, up-to-date, runtime.

Community
  • 1
  • 1
jscs
  • 63,694
  • 13
  • 151
  • 195
5

I think I understand your question correctly, so I will answer accordingly...

I highly recommend the documents in the Apple Developer Library. Here are a couple basic guides to get you started:

Concepts in Objective-C Programming

Programming with Objective-C

Cocoa Fundamentals Guide

iOS App Programming

The documents there are the definitive source for Objective-C and Cocoa best practices and coding standards. There are many more documents on a multitude of topics, so make sure to check that website out.

You also asked about how to know what methods are available for objects. To know that, you can check out the Class References.

For example:

NSObject Class Reference

The difference between the guides and the class references is that the guides are more about the concepts behind the code whereas the class references are a list of the methods and properties available for a class.

Hope this helped.

Marcel Beemster
  • 183
  • 1
  • 4
pasawaya
  • 11,515
  • 7
  • 53
  • 92
1

Found at least some of the language definitions of Objective-C, including syntax etc. (see link)

I'm just now where you have been 3 years ago (according to the date in your question): I'm starting to get into Objective-C, and I find it as well strange that there seems to be no reference manual, where I could for example look up the exact meaning and definition of syntax, keywords etc.

I've now discovered, that at least some of it can be found in a document which is related to cocoa (Cocoa Core Competencies). The link for example jumps to the definition of the keyword "@property".

In my POV this is not only relevant only specifically to Cocoa but is generally defining the Objective-C language extension of C. Thats why I wouldn't have searched for it in documents labled "Cocoa ".

dewege
  • 11
  • 1