Two OS X with swift questions

I’m new to Mac, OS X and swift. I’ve done some work with Windows and C# a few years ago. OBTW, Cocoa Programming for OS X was very well done and useful. I’m not quite done with it yet, but it’s a great place to start.

I understand Xcode 6, the value of the IDE and all that, however, i’d like to write a program in swift using a context sensitive editor, compile it to an executable, and then run it from the command line. I’m not seeing anything online or in a couple books I’ve read on how to do that. I guess I can make due with a simple window app if that’s the best way to go. Is that what the command line Application project in Xcode 6 is all about? Any ideas?

Also, I’m not seeing much on simple binary or text file routines for creating, opening, writing, reading, … in swift. I see the NSStream class, but I need a little more help with it than whats available online. Anyone have a good resource? Thanks!

That’s pretty easy to do in Xcode. You can create a tool in Xcode, and run it from the command line as outlined below.

  1. Create a project for an OSX Application by using the Command Line template and by choosing Swift as the language.
    You will have a single Swift file for the ubiquitous Hello, World! program, (in Xcode Version 6.3.2 (6D2105.)

  2. Build the product.

  3. Locate the binary for the product as follows:

    • Activate the contextual menu on the product under the Products group in the navigation area, and select Show in Finder.
      This will open the folder containing the binary file.

    • Start up the Terminal application, and change the working directory to that folder.

    • Run the binary: ./
      For example: ./MyCommandLineTool

    • Enjoy watching the output of your masterpiece :slight_smile:

[Become a competent programmer faster than you can imagine:]

Got it, thanks!

you may also be looking for this which shows how to program in swift without xcode at all.

You can also use it like a scripting lang.

[code]#!/usr/bin/env swift

print("hello world!!)[/code]

put that in a text file. chmod +x it. and you can run it from the command line.