How to use classes defined in other files in Swift script

I have a Swift script "main.swift" which I created by adding

#!/usr/bin/env xcrun swift

      

to the beginning. Moreover, I chmod + x'd to make it executable.

Inside the script, I would like to use the Swift class "A" defined in another file "A.swift" contained in the same parent folder "main.swift".

Just using "A" inside "main.swift" doesn't work.

Any ideas on how to achieve this?

+3


source to share


1 answer


This post asked a similar question, the solution was to merge the files with a shell script:

TMPFILE=`mktemp /tmp/Project.swift.XXXXXX` || exit 1
trap "rm -f $TMPFILE" EXIT 
cat *.swift > $TMPFILE
swift $TMPFILE

      



I haven't tested it, so I don't know if it works.

0


source







All Articles