Objective-C Experience

Hello Internet,

So I did a little project in Objective-C with Xcode and there where some things that made me furious, after a while I just started a list with pain point’s. So without further ado, here is my list:

(Necessary disclaimer: I do not claim to be an expert and that every problem I mention are probably my fault, but if that’s the case you can write me an mail)

(Also necessary disclaimer: I know that objc uses message-passing, but the nomenclature with method just sticks with me, so sorry about that)

I will start with Objective-C:

  • Syntax: [foo barWith: qux];: I really appreciated how you have to type the parameter name and that somehow makes writing fluent and in general nice to read, but packing the whole thing in square brackets costed me a lot of nerves and time. It really didn’t help that to access a properties you don’t need them (e.g. qux = foo.bar;) and since I never knew if I need to access a property or that I need to call a “method” I always missed the brackets.

  • One of the things that really confused my was nil. If one of my programs in Java or C++ calls an null reference I either get an segmentation fault or an NullPointerException, but not in Object-C. nil just accepted every “method call”, but it does not fail…

  • NSArray declaration with a nil terminator. I mean [NSArray arrayWithObject: foo, bar, qux, nil] come on…

    Present Me: @[foo, bar, qux] is what I needed.

  • alloc and init. I noticed that the Apple framework tries to get around those. I mean you want to create a object, which is in e.g. C#/Java one call with the constructor, but in objc to achieve the same result you have to invoke two different “method’s”. One thing that stuck with me was the strange way you implement your own init “method”:

- (id) initFoobar {
  if(self = [super init]) {
   //initialize fields

  return self;

In contrast C#/Java:

public Foobar() {
 //initialize Fields
  • Formatting of big Header-Files. To me it looks like that in objc you don’t add tab/spaces after you declared an @interface. Well now it’s super difficult to figure out, when an Interface ended and a new one started.

  • Ever tried to put an enum inside a NSDictionary? It’s good that you can give them an type-parameter, but an enum can only be put as an (NSNumber *) into the Dictionary. I mean from the technical point of view it make’s sense, but I really missed some syntactic sugar here.

  • Both in C# and Java I put an (key,value)-pair in an Dictionary/Map, but not in objc here it’s an (value, key)-pair.

  • At some point I had to work with the following Dictionary NSMutableDictionary<NSNumber *, NSString *> dictionary and I tried to add the values with [dictionary setValue:foo forKey:bar];. After my logic was implemented I saw that I had an compiler warning “Incompatible pointer types”. The types of foo and bar where correct, so I recompiled, ran the unit-tests and the program to check if it was an old warning, but the warning stayed. It took me a while, but eventually figured it out, I used the wrong “method”-call the correct is [dictionary setObject:foo forKey:bar];. That warning really questioned my sanity… But now I question why there is a “method” declaration ignoring my type-parameter…

  • Do you know the feeling when you look at your own code and don’t have a single clue what the code does? It happens, but in Java you mostly can differ between a helper-method (which is mostly private) and an method that will be invoked from the outside (which is probably public). In objc I really missed this, when every “method” starts with - (type) ... it gets really difficult to separate an helper-”method” from an “method” that will called because your class extends UIViewController.

  • The fact that I need to write @interface and @end instead of class {} gave me the feeling that objc is only a second-class citizen to itself and instead of objc I should use plain C. It really degraded the whole language for me.

To Xcode:

  • I don’t know but somehow the whole auto-complete was completely confusing for me:

    I already wrote that a “method” call is packed inside square brackets. At some point I realized I do not need to place the first bracket. If you close your “method” call with an ] Xcode will add the first bracket for you. That really helped, but if you’re inside an “method”-call this will not work.

    I really wished Xcode would at least make clear that the highlighted member is a “method” or a “property” but I didn’t see any hint for that. The whole half-functioning auto-complete and missing hints for what’s the current member added to my confusion around the whole square-brackets problem. I guess that the syntax weren’t a problem, if Xcode would be better in that regard.

    Another Example: I’m inside an *.m file and I wanted to write-out the implementation for a interface. I always started with @imp and hit Ctrl+Space and the only suggestion Xcode could made was @import. Do real objc developer don’t to implement interfaces?

    Present Me: I recognized that the Mac at my work does return the awaited suggestion-list, are there configuration missing?

    I already mentioned I’m not the smartest guy and I always forgot the members I declared earlier, but every time I used the auto-complete feature to search for my property with Ctrl+Space Xcode presented me an alphabetic sorted list of everything the class was capable, with like +20 entries. To find my member I either searched for a minute in that list, or simply jumped to the declaration. As an counter-example: In Intellij-IDEA the overwritten members will be presented in bold and first, that would really helped me.

    And whats with the support for class-comments? I mean as far as I know, there is no official “Obj-C-Doc” like “JDoc”. but one should use e.g. Doxygen, that’s fine for me but it adds to the problem. My actual point is, does Xcode has any auto-complete support for comments? I mean for me Xcode wasn’t even able to add * or */ after I wrote an /* and hit Enter! I guess at that point it’s to much to ask for an * @param foobar auto-complete feature.

  • ?: The project relied on a lot of asynchronously executed logic handled with selectors. The thing that stood out for me was, e.g. I setup an timer and give him the selector, and when I tasked Xcode to jump to the declaration, a ? popped up and nothing happened… The same with #define magicNumber 21. Xcode wasn’t able to find where magicNumber was declared…

  • One thing that really stood out for me, was how you where supposed to bind Storyboard-Elements (xml-file which describes the visual-part of your app) with your Controller-Code. A View could be bound to a specific UIViewContoller which was pretty straight forward for me, but to add an click-event to your UIViewController you had to perform the following steps:

    1. Change Xcode to Assistent-Mode (which half’s the visible space from the storyboard and of course changes your viewpoint. The new second-half of your editor is now another random(?) class-file)

    2. Open your UIViewController in the assistant-window, which isn’t done with the project-explorer (That only works with the main window), but with an different ui feature I didn’t know existed.

    3. At last, you have to press Ctrl and click on your button in the Storyboard and “drag” the button to the code…

    4. Finally Xcode opens an popup asks for the “method”-name and generates your new “method”-stub.

    I’m really not the guy who watches instructional videos on YouTube, but I really couldn’t figure it out without those…

Final Words

I guess objc does the job, but if you’d ask me if you should use objc I would probably said “only when your customer forces you to use it”. Xcode… Well not everything was bad, I was really happy that it helped me with an designer for the storyboard also testing, compiler and project management where good, but for the actual coding it lacked features.