To get started with Swift, download the latest Xcode 6 version.
Once you have completed installation of Xcode 6, Follow the steps to create a command line application.
- Open Xcode.
- Select File -> New -> Project.
- In the new window that appears, Select Applications under OS X.
- Select command line application and press Next.
- Enter “Product Name” and press Next.
- Select location to save for your new project.
Now, you will find a main.swift file created for you. It contains a Hello World example by default as shown below.
import Foundation println("Hello, World!")
When we run the above program, we will get the following result in the debug console.
The println is used print any statement in a new line. As you can see, you don’t need a semi colon to terminate the statement. Use NSLog function, if you want to log in a special formatted log with time and application name.
Note to Objective-C developers
Unlike NSLog, println don’t add the time during which the log statement was executed. For strings including the one used in NSLog(“string”), never use @ symbol as in Objective-C.