Follow The Script: Scripting in Swift
Getting started with scripting in Swift? This article takes a quick look and points you in the direction of some materials to help get you going.
Join the DZone community and get the full member experience.Join For Free
Between writing our client apps in Swift and looking forward to writing our server apps in Swift, we tend to overlook that Swift can be used as a scripting language as well—seriously, is there anything it can’t do? So, here’s how you do that using Xcode:
First, you’ll need to start with a new Xcode OS X Command Line Tool Application … The cool part here is that you can even import frameworks like Foundation. Anything you can do with Foundation, you can put into a script — this includes File I/O, string manipulation, and more … Your script can even accept arguments. Just append whatever you want after your execution command to add your arguments like a regular script…
Scripting is a powerful asset and a useful tool in any programmer’s tool belt. For many iOS Devs, Swift or Objective-C are the only languages they know. If they know Swift, then there is no need to learn Python or another scripting language when writing simple scripts for any automation process.
End-to-end development and deployment with nothing but Swift? Shiny!
Another introduction here:
A shell script is perhaps the most popular command-line scripting language, particularly in the mobile development world. To test the viability of scripting in Swift, we’ll write our markdown converter first as a shell script and then compose a Swift version. We’ll then do a quick comparison of the pros and cons of each script…
We started using both CocoaPods and Carthage to manage our dependencies, and we wanted to add a nice little view in our app that shows a list of open-source acknowledgments and licenses. We have around 20 dependencies, and the thought of adding the acknowledgments manually sounded tedious…
Indeed, it is. Well, that’s definitely our first experiment in integrating Swift scripts into our production process, then!
Published at DZone with permission of Alex Curylo, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.