Tech Reflect

Tech Reflect

Share this post

Tech Reflect
Tech Reflect
Creating human-readable Swift tool with Xcode

Creating human-readable Swift tool with Xcode

Chris Hynes - cricket's avatar
Chris Hynes - cricket
May 10, 2018
∙ Paid

Share this post

Tech Reflect
Tech Reflect
Creating human-readable Swift tool with Xcode
Share

One of the (few) nice things about a shell script is that if you share it with someone, they can look at the source code and see how it works or modify it for their own purposes.

It’s not as quick and dirty as a bash script, for example, but it has some big advantages:

  • It’s Swift and it’s a great way to learn it and reduce the number of languages you need to know

  • You can use Xcode to create the tool and have the full power of Xcode debugging

  • Writing tools in bash can be very frustrating due to the unusual syntax and lack of some modern language features.

There’s one downside though. The output from Xcode is a compiled binary, so people have to check out your source code from a repository to see how it works. So, here’s what you can do after you’ve created your project. A caveat is that you must keep all your code in main.swift for this to work, which is probably likely anyways for a tool.

At the top of main.swift, add this line:

#!/usr/bin/swift

This is ignored by the compiler.

  • Click on the pr…

Keep reading with a 7-day free trial

Subscribe to Tech Reflect to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Christopher Hynes
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share