DEV Community

Nicolas Verinaud
Nicolas Verinaud

Posted on • Edited on

2 3

My new swift workflow or how to boost your swift productivity !

Running tests manually each time I make a change in Xcode or AppCode drive me crazy (because of slowness & bugs in AppCode), so I decided to automate it.

The objective ? Having this kind of workflow (which I observed and enjoyed when I did some JavaScript) :

  1. edit some source code,
  2. watch the tests run automatically without me doing anything, giving me instant feedback on how well I am doing.

Here is how I enable this workflow for swift development (it can also be applied for other languages as long as you can run tests from the command line) :

  1. Install node
  2. Install nodemon
  3. Run this command in your workspace (or project) folder (using your favorite terminal or the one embedded in AppCode, which I use because of me working in full screen).
nodemon -e swift,strings --exec "xcodebuild -workspace MyApp.xcworkspace -scheme \"MyApp\" -destination 'platform=iOS Simulator,name=iPhone XS,OS=12.1' test"

Just replace the workspace & scheme with yours, and you're done ! You can make a change to any swift or strings files and boom tests are run automatically !

Let me know how if it is helpful for you in the comment or on Twitter !


I originally wrote the full story (with drama) of me making this possible. I left it below for you to enjoy ! 😁

The Full Story Behind

It all started with a frustration.

I love the speed of Xcode for building & running tests.

But, woa, the refactoring capabilities, despite getting better, are wayyy behind what AppCode provides.

I love the refactoring capabilites of AppCode.

But, woa, building & running tests is so sloooow.

And it fails every once in a while, like, every hour with a "db lock blabla" error requiring me to clean, clean build folder, praying, crying, relunching the IDE, crossing fingers. Eventually productivity is back again.

Choose your pain !

A Great Ide(a)

So, yesterday I had an idea.

Wait wait, building your own IDE right ?

Exactly !

You know that this is a huge project, like a HUGE project !

Yeah, cool isn't it ?!

You do not have the time to do that.

What ? ...

Oh I guess you're right. Am I doomed ?

You're a developer, a developer is never doomed ! What about finding a viable solution in 1 hour ? Like a Startup Challenge !

Challenge accepted !

Wouldn't it be cool to use AppCode as the source code editor & Xcode to build & run the tests ?

That would be my MVP.

Switching back & forth between 2 IDEs manually ? You kiddin', right ?

Meh...painful isn't it ?

What about "build & run" from the command line using the integrated terminal of AppCode ?

Seems better !

So my solution is only a little man xcodebuild away !

*Digging into the manual*

TADA! Here is my command !

xcodebuild -workspace MyApp.xcworkspace -scheme "MyApp" -destination 'platform=iOS Simulator,name=iPhone XS,OS=12.1' test

Seriously ?

Yep ! My workflow is now :

  1. Editing some source code
  2. Running the command above
  3. goto 1

Not bad, but I have another challenge !

I have some time left, tell me.

What about running this command automatically when you edit the source code ?

Hum...

I did this thing one day...nodeJS...
...with a watch running stuff when code changed...like hot reloading, running tests...

Cool story... But this is serious stuff, not this JavaScript hype thing.

I am serious !

Oh yes I am...

So it used an npm package called nodemon to watch for file changes.

*Searching for nodemon...digging into the documentation*

TADA! I can run this nodemon thing telling it to watch for swift & strings files & executing my custom command !

Prove it !

No problem, watch this !

nodemon -e swift,strings --exec "xcodebuild -workspace MyApp.xcworkspace -scheme \"MyApp\" -destination 'platform=iOS Simulator,name=iPhone XS,OS=12.1' test"

Oh please, you mean your workflow now is...

  1. Editing source code
  2. No step 2.

Lessons I learned

  1. Frustration is a powerful call-to-action for me.
  2. Learning unrelated stuff, like nodeJS in this case, can open new horizons & improve creativity.
  3. Using the 1-hour timebox forced me to find a good enough solution which ended beyond my initial expectations !

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more