Reputation: 47
I started writing a basic swift script file and compiling it as:
swiftc *.swift -o exporter
Script doesn't do anything right now, but will have export
, import_files
etc. functions. I'm trying to find how I can test this basic script file?
Ideally, I'd have an exporter_test.swift file which I have all my unit tests. Also, it's important to note that I'm fairly new to swift, so not sure if this is doable outside of Xcode.
exporter.swift
func export() -> {
// will do exporting of data that's been imported in import_files
}
func import_files(files: [String]) -> {
}
Upvotes: 2
Views: 583
Reputation: 2251
You could execute it using the "swift" command line utility:
example:
Create a file (test.swift
) with the following contents:
import Foundation
debugPrint("hello!")`
Then from the command prompt just run it with:
swift ./test.swift
and you should get:
13:24 $ swift ./test.swift
"hello!"
Form within Xcode if you wanted it to execute via the build stages, then you'd have to add a "run script" stage.
Project Navigator
(on the left)Build Phases
tab+
to add a new phase and choose `New Run Script PhaseJust note that in 5.
above, you'll probably have to rely on the build-time environment variables to reference files. Directly referencing a file i.e. as I did in my example will probably be caught up in a sort of "chroot" where /
isn't actually /
but rather a folder relating to the build directories.
Upvotes: 2