Saturday, 15 February 2014

command line - How to Import modules without an Xcode project in Swift -


I use one of them to create swift files and use the command "swift" command line I am here. However I want to be able to access a file from other file functions. If it were, then I could include the #macro and specify where the file is, but the statement of Swift's import does not seem to be there, there should be a way and I would like to know how to do this. For example:

If I have a file with a function and then I create another file uses that function how do I allow it to be used?

  // file1.swift Import Foundation func sayHello () - & gt; String {return "hello"} // file2.swift import file1 // & lt; - File 1 is trying to import but this println (sayhelello ()) does not work  

Once the file has been created, I write in the "swift file2.swift" terminal I am But it tells me ..

  Error: Such a module 'file1.swift'  

Clearly the fast compiler is looking for a module . How do I create file1 in a module? I have seen some solutions but they all take place in Xcode. What I am seeing is to do all this in the command line.

  // File1.swift func sayHello () - & gt; String {returns "hello"} // main swift println (sayHello ())  

and then from the terminal:

  $ swiftc file1.swift main White $ ./man Hello  

No comments:

Post a Comment