Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Scripting Autocomplete

After finding a number of articles that describe using Apple's Swift for scripting purposes, I wanted to try my hand at it. I want to do some simple scripts that perform actions on the file system: moving things around, renaming things, and so on.

My preferred text editor is Sublime, and while there is a package for Swift syntax, you obviously don't get any kind of autocomplete. Alternatively, I could use Xcode, which historically has had awesome autocomplete. From the command-line, I can type open myFile.swift to pop open an Xcode editor window for that file.

However, when I do this there's no autocomplete. I fear that I need to have a whole Xcode project set up with a build target, etc. to get autocomplete going...is this the case?

Does anyone know a simple way to get Swift autocomplete in Xcode (or Sublime) for scripting purposes? Thanks!

like image 461
Matt Mc Avatar asked Jan 24 '15 21:01

Matt Mc


2 Answers

You should try using a playground in XCode if you don't need to reference other files. This lets you perform some basic debug as well.

like image 192
desilvai Avatar answered Oct 01 '22 04:10

desilvai


After checking the help command with swift package --help I noticed about the generate-xcodeproj subcommand:

generate-xcodeproj      Generates an Xcode project

So, you can generate an Xcode project doing swift package generate-xcodeproj and benefit the awesome autocompletion that Xcode gives you, even using dependencies.

Just generate and open the project file. Resolving new package dependencies will not update the project, so you need to rerun the generate-xcodeproj command on every dependencies change.

like image 39
ricardopereira Avatar answered Oct 01 '22 03:10

ricardopereira