iOS Pain Points: Constants and enums are not discoverable

Let’s say I want to use a UIImagePickerController to take some photos.

UIImagePickerController* controller = [[UIImagePickerController alloc] init];
controller.sourceType = 

Ok, I’ve finished typing the = sign on the second line. Now I would like to type the actual source type value that I am assigning. Surely Xcode can help me out with this? I mean, intellisense/content assist/code completion is a pretty basic IDE feature. But Xcode does nothing by default. Ok, fine. I’ll hit Esc to manually invoke autocompletion.

Xcode, in all its wisdom, gives me a completely useless list of dozens or hundreds of irrelevant entries.

Fine, I happen to know that enums generally start with the name of the control. I will manually type in ‘uiimagepickercontrollers’, to finally get a list of the available UIImagePickerControllerSourceTypes. All in all, it’s a horrible user experience.

Now let’s move on to something even worse. It’s time to configure my controller’s media types:

controller.mediaTypes = wtf?

Ok, so mediaTypes is an array of, well, stuff, since Objective-C arrays aren’t strongly typed, as we saw in the previous ‘iOS Pain Points’ entry. So I have no information on how to use this API, and code completion is telling me nothing. No problem, I’ll just look at the Quick Help window in Xcode.

Great, it’s ‘An array’. Thanks, Xcode. Not to worry, though. I’m familiar with the standard mentioned above, where types generally start with the name of their control, so I’ll just look for UIImagePickerControllerMedi… ok, scratch that. Turns out, I actually need to use a constant such as kUTTypeImage, which is declared in a different file. Or to put it another way, it’s literally impossible to use the UIImagePickerController without looking at the documentation to figure out what the allowed values are for what fields. It’s a case study in poor, non-discoverable API design and inadequate IDE integration.

For reference, here’s what using an enum in C# / Visual Studio looks like:

Apple could learn a thing or two from Microsoft here.

3 Comments

  1. my point exactly from the beginning of my oc xcode experience. there is no IDE comparable to VS up to now.

    Reply

  2. I know this is an old article but on a search for the enum autocomplete problem I came across this. I thought I must be doing something wrong and or I am missing something obvious.

    In VS this sort of thing is just so simple it fades into the background and just works, helping you code. I can’t believe I just said that about a Microsoft product in comparison to an Apple one but as you said, Apple could really learn a lot from the VS team.

    Reply

Leave a Reply to nevin Cancel reply

Your email address will not be published. Required fields are marked *