Objective-C standards document - objective-c

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

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.

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.

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 ".

Related

How does Objective-C get updated? Are there versioned releases? What is the current 'version'?

I have been trying to answer this question and looking at google/wikipedia etc but have not been able to determine this. On wikipedia I see a reference to Objective-C 2.0 but thats about it. I am curious for example in Xcode 7 there were some new features available for Objective-C like lightweight generics and __kindof. Did these exist before and they were just made available via Xcode in v7? Or did the language change? I tried to find a version history or information on releases but so far have come up with nothing. Swift is clearer on versions/releases and I keep asking myself if I am missing something related to Objective-C since I can't find this information. Does Objective-C update with Xcode releases or can the language evolve on its own?
in Xcode 7 there were some new features available for Objective-C like lightweight generics and __kindof. Did these exist before and they were just made available via Xcode in v7? Or did the language change?
To that extent, yes, the language did change.
The best way to research this sort of feature is by going through the Release Notes for Xcode. Thus, the features you are talking about appear here:
https://developer.apple.com/library/content/documentation/Xcode/Conceptual/RN-Xcode-Archive/Chapters/xc7_release_notes.html#//apple_ref/doc/uid/TP40016994-CH5-SW1
There is actually an Objective-C section with a subsection "Objective-C Language Changes". That pretty much tells you this was a change in the language!
Changes since then are listed here:
https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html
Of those, the most significant is probably the advent of class properties.
All these changes took place primarily to enhance Swift compatibility, and I think we may expect that all changes in Objective-C going forward will be for that purpose.
Objective-C is a very simple language. It's just a very thin layer on top of the C language. It's very important to realize that if C changes, Objective-C also changes. You can actually select which C dialect will be used for your Obj-C compiler. In that sense Objective-C changes all the time.
If we are speaking only about the object layer, there is no official specification, no discussion groups (e.g. as we have for Swift). It's not open-source. Practically speaking, current Obj-C features are exactly what the Apple's version of LLVM-Clang compiler has implemented (that is, what is shipped with Xcode). And LLVM documentation is where you can find the most interesting pieces of information about Obj-C features.
Obj-C changes a bit with every Xcode release although nowadays new features usually mean more attributes/annotations that can improve code analysis and provide more information to Swift. There is no official version number.
Objective-C has reached a state when it can't be really improved any more. It needs to support everything in C, it has to be backward compatible and its dynamicity makes it very hard to check types. That's exactly the reason why Apple has introduced a new language.

When analyzing a binary compiled from Swift, is it possible to figure out the Swift method name for a function that has no symbol?

I'm new to disassembling and reverse engineering binaries, so forgive me if this question is nonsensical or impossible.
In the past when I've tried reverse engineering macOS binaries, analyzing the ones written in Objective-C yielded a lot of useful information, because generally all of the Objective-C classes and their method names were easily retrievable, making it a lot easier to figure out what any particular method did.
I'm trying to analyze a binary written in Swift (technically a combination of Swift and Objective-C), and most of the functions now have no symbol. There are some Objective-C methods that I can retrieve as usual, and a few functions that have a Swift-style mangled name, but nearly all of the rest have no symbol. I know a lot of those have to be Swift methods.
Is there anyway to figure out what this binary's Swift classes are and their associated methods like I can with Objective-C?
Using a tool like Hopper Disassembler reveals the mangled names of some Swift classes (usually a symbol like _TtC4Something25SomethingElse) and I can get a list of its instance variable names and their offsets, but no method names.
Note: the binary in question is an x64 macOS binary, not an iOS binary.
Usually reverse engineeing is the process of extracting meaningful constructs and descriptions from assembly. What you've done so far is usually only the first part of a "normal" reverse engineeing task.
This may sometimes be a tedious process, which involves mapping structures and understanding the meaning of functions directly from thier assembly code.
There are pleanty of reverse engineeing tutorials and other sources, and a good understanding of the relevant assembly language is required.
I really recommand this book (it's legally available online, original version is chm released by author) and this cannot easily be covered in a single SO question.
You might also want to get more specific help in the reverse engineeing SE beta.
I hope I pointed you in the right direction.

Why doesn’t Objective-C have namespaces?

Why doesn’t Objective-C have namespaces? It seems like a simple feature that would make some class names more readable (AVMutableVideoCompositionLayerInstruction anyone?) and axe the silly letter prefixes on class names. Is this mainly because of backwards compatibility? Is it harder to implement namespaces than it seems?
I don't know the answer but I suspect "it's harder than it looks" is probably it. You would have to introduce support in the compiler and linker in a way that doesn't break existing software. And while this is obviously possible (C++ has already done it) presumably the tool chain team have had higher priorities on their plate. e.g. in the recent past we have had garbage collection, GCD, blocks and Objective-C 2.0 appear so we can't say they have been doing nothing.
Namespace support is the one thing that I would dearly love to see introduced to Objective-C.
I don't know if you want to know if there is some official decision.
But namespace like many other feature are choice, choice made by the language contributor.
PHP only recently introduced Namespace, and for example Java use package that act like namespace or python use modules.
I think that there is an overhead in namespace implementation, mainly because Objective-c is dinamically typed so at runtime you have to make some check to resolve the namespace, to resolve default behaviour,etc.. and I can suppose that because Objective-c is also used in embedded enviroment (AKA iPhone) speed is very important.
You've to wrap everything I've said in a big IMHO ;D
Update:
I found this very interesting discussion http://clang-developers.42468.n3.nabble.com/Adding-namespaces-to-Objective-C-td1870848.html#a1872744 on the clang developer website explaining the reason why is definitely non-trivial to implement namespace in Obj-C.

Objective-C implementation of Shape Context algorithm (Image Matching)?

There is a very cool sounding technique called Shape Context matching, which can be used in an Image Recognition application to match an "unknown image" against a known "image library." There are numerous descriptions of the concept documented on the web (mostly all variations of the same original paper), for example: http://www.eecs.berkeley.edu/Research/Projects/CS/vision/shape/sc_digits.html
I found a JAVA implementation and a MATLAB implementation of the algorithm described in the paper, but I cannot find an objective-c implementation. Anyone know if there is any objective-c code out there, anywhere, implementing these techniques? I sure would like to take advantage of it, rather than trying to write that stuff myself!
Here you can find an interesting c++ implementation (for non-commercial usage, didn't check it yet.. see the downloads):
http://www.umiacs.umd.edu/~zhengyf/PointMatching.htm
I'm currently searching for a Java implementation of the algorithm. Could you please provide a link to the implementation you found?
The original matlab code can be downloaded at:
www.eecs.berkeley.edu/Research/Projects/CS/vision/shape/sc_digits.html
I also found a C# implementation:
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=7465&lngWId=10
Take a look at OpenCV. It is implemented in C so it can be used in obj-c pretty easily.

Programming features missing in C++ and Java

What are the programming features that are missing in C++ and Java ?
For eg. You can't do recursive programming in QBasic ? You can't dynamically allocate memory in QBasic.
What would be the good to have features in C++, Java.
I think Lisp Programmers will be able to add a few.
I miss lambda expressions.
This answer deals only with C++
Things I miss from the syntax, or the standard library:
RegExp as part of the standard library
Threads as part of the standard library
Pointer to member methods (not objects!)
Properties would be nice (I have seen codes that emulate this via C++ preprocessor... note an nice looking code).
Some lower level networking API (sockets!), and higher level API (give me this file from this ftp, submit "this" to this site via POST).
This is the list of things I would like to see, but I assume other people will disagree with me.
Memory garbage collector is nice.
A n interface for a GUI toolkit - let MSVC map it to win32, and on Linux... (good question!)
A stable ABI. In C it's a standard - but on C++ we are still missing a few decades. I want also stable ABI between compilers - I want to compile one library in MinGW, the other with CL and all should work.
This is the list of things I want to see, but I know they will not get away:
Compatibility with C. Really, it's a myth right now. using namespace std killed it.
Include, headers. Most of the information is already available in the DLL/so/a/"library", do we really need to keep this bad decision from 30 years ago? If needed the compilers should keep information in the binaries.
The need for Makefiles - the compiler should be smart enough to know what to do with this code, from the code itself. Pascal is doing it quite good. I think also D.
(I might be wrong, please correct me) The official standard openly and freely available for viewing. Why should I pay for the official papers? Do I need to do it for HTTP? UTF8? Unicode?
I think this is a very subjective question. From a theoretical point of view there's nothing "missing" in Java because you can do everything you want to from the perspective of the outcome as an application.
As with QBasic - recursion may not be possible but that doesn't prevent you from changing your recursive algorithm to an iterative algorithm. Programming language theory tells us that you can do this with every recursive problem. So there's also nothing missing here.
I think what you mean are features that are "nice to have" - and here everyone has to decide for himself. I'd even say there are features in the language which would have been "nice not to have" such as static imports - but again this is my subjective opinion...