2

I want to run a simple swift program on the command line.

I have the following files:

~/calcs/demo.swift (is executable)

#!/usr/bin/env xcrun swift

import Foundation
import calcs

println(aString())

~/calcs/stringFunctions.swift

import Foundation

public func aString() -> String {
    return "1234";
}

If I invoke it $ ./calcs/demo.swift it errors with ./calcs/demo.swift:4:8: error: no such module 'calcs'

If I replace it with import stringFunctions it similarly errors. Or if I comment out import calcs then it errors with use of unresolved identifier 'aString'.

If I set FRAMEWORK_SEARCH_PATHS to the parent directory ~/calcs or ~ it does not successfully find the module either.

$ xcrun swift --version
Swift version 1.1 (swift-600.0.57.4)
Target: x86_64-apple-darwin13.4.0
AJP
  • 26,547
  • 23
  • 88
  • 127

1 Answers1

1

As @dmdm stated the correct answer is here and was to rename demo.swift to main.swift and run:

$ swiftc ~/calcs/stringFunctions.swift ~/calcs/main.swift
$ ~/calcs/main.swift
1234
Community
  • 1
  • 1
AJP
  • 26,547
  • 23
  • 88
  • 127