KSImageNamed: Xcode autocomplete for imageNamed

A few months ago I discovered and installed ColorSense for Xcode, which set my mind to thinking what other common annoyances or inconveniences be improved in Xcode. It took me about three and a half seconds to jump from colors to images, as Xcode doesn’t autocomplete imageNamed: calls. It’s impossible to remember the names of all the images in a project, especially when there are a hundred or more images. Switching to the Project Navigator to check if the image is named button-highlighted-pressed.png or button-pressed-highlighted.png gets old quickly. Additional trips to check whether an image’s 2x representation is added to the project only makes matters worse.

Armed with a new idea, a few free hours, and class-dump, I sat down and started hacking. I figured out how to insert items into Xcode’s autocomplete lists, ran into a couple of roadblocks, quit for the day, and then promptly forgot about the matter entirely. And so the project sat and collected dust, as code is prone to do. Finally, last week I forgot the name of one image too many. So I now present to you KSImageNamed, an Xcode plug-in for getting the imageNamed: autocomplete that should have been there in the first place.

KSImageNamed in action

Want NSImage/UIImage imageNamed: autocomplete bliss in your copy of Xcode? Go clone and build KSImageNamed on GitHub.

Hopefully this will save you a little frustration the next time you type imageNamed: and can’t remember the name of the image you were about to use. Even better, maybe this will get some people thinking about scratching an itch and making Xcode a little more pleasant to use. If there’s any interest, I may do a follow-up with some details on how the plug-in works so others can start hacking on Xcode themselves.

9 comments

  1. Ryan Poolos

    OMG I love you. This is incredible. A follow up beginners looking to hack Xcode for custom plugins would be awesome. Would love to start working on improving Xcode.

  2. Christopher Truman

    This is seriously beautiful. I don’t want to know how much time I have wasted on bugs caused by me typing the wrong name for my file or similar mistakes. All iOS developer should bow down and give you a dollar. I hope to see more plugins like this! I also hope Apple makes it easier to make plugins than method swizzling and class dumping.

  3. Gregory Moore

    You ROCK, Kent. What an incredible timesaver. Totally appreciate you taking the time to make and share this awesome tool!

  4. Uli Kusterer

    I’m a bit wary of Xcode plugins, but that’s not your fault. This is a great use of one, thanks! One idea: Would there be a way to configure what calls’ parameters should get the benefit of this?

    I.e. for window controllers and their setWindowNibName: and initWithWindowNibName:, it’d be great to be able to get this auto-complete there as well. Even any custom classes where I have setImageName: or whatever methods.

    I guess if Apple did it, they could add something like NS_FORMAT_FUNCTION() for project resources (maybe even of arbitrary types). But even just a plist to enter which methods get what type of resource would rock.

  5. Kent Sutherland Post author

    Ryan: Glad you like it! I’ll see if I can put together a more detailed walkthrough of how this works. It’ll give me something else to post here :)

    Uli: That’s definitely a good idea. I imagine it wouldn’t be too difficult to use some sort of plist or other definitions file to provide autocomplete for other file types. Right now imageNamed is just hard-coded, but easily replaceable. At the very least it’d be nice to abstract that out and provide a single place to replace imageNamed with something else.

  6. Gustavo

    +1 on a writeup on how to create XCode plugins. If you’re looking for a potential idea: Have a way to “pin” tabs as with Chrome. I’d love to have tabs that do not allow me to change the loaded file ….

  7. Rob

    Great article this project is great. I would also be interested in a post about writing plugins for XCode.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">