Code Injection for Xcode 8 in CollectionViews and TableViews

Screen Shot 2017-02-25 at 1.30.35 PM.png

I finally got sick enough of my load times 😭 in Xcode that I went looking for a solution.

I had heard about this code injection plugin for Alcatraz which looked promising.  But to my dismay, I soon realized that all plugin support had been dropped for Xcode 8.  Sigh.  But wait! What's this here?  A code injection app for mac?  Let's investigate.

John Holdsworth, the creator of the code injection plugin, has released a code injection app that can interact with the Xcode simulator when both are running at the same time.  Fantastic!  I downloaded and installed it.  Also, this fantastic code injection intro video was attached to the site, but later taken down. I wish it hadn't because I had to go looking for it again.

Does Code Injection Work in Production Code?

My only problem was that a struggled a bit to integrate the code injection app into my workflow.  Like most iOS developers, I'm working with UICollectionViews and UITableViews on a daily basis.  Could I use the code injection app there?  That's where I really needed it.

As it turns out the answer is yes!  I made a quick little video to show how easy it is, but you can also see the take-aways below.

How to use Code Injection:

  1. Install and run the injection app from here.
  2. In any subclass of NSObject (like UIViewController) add the function below.
  3. Compile and run your app
  4. Once the app is loaded you can change the UI code in your table or collection
  5. Press (Command + S) to save
  6. Press (Control + =) to run the injection script
func injected() {
    collectionView.reloadData()
}

A few things to be careful about:

  1. If you're using a tableview, all you have to do is change the injection code to tableview.reloadData().
  2. Make sure to run the injection script while the file that contains the injected() function is open in the Xcode window.
  3. You can change files other than the one you're working on and still have your UI Code update from the injection script.

And there you have it! I'm a huge fan now that I've saved myself nearly 30 seconds of compile time for every UI change I make.  A big thank you to John Holdsworth for making such a great app.