KSImageNamed: Xcode autocomplete for imageNamed

January 22, 2013

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.

spacer

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. spacer 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. spacer 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. spacer Gregory Moore

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

  4. spacer R.B.Niranajn

    Really it is imaging . It is time saving.

  5. spacer 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.

  6. spacer 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 spacer

    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.

  7. spacer 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 ….

  8. spacer Rob

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

  9. spacer Austin

    Wow, fantastic. Thanks so much for sharing.

Comments are closed.