How to build a simple “Hello World!” Cocoa OS X Application in Swift

Start Xcode (Version 6.1.1). Xcode is an Integrated Development Environment for mac OS.

Main Menu > File > New Project

Under “OS X” choose “Application” and then “Cocoa Application” (this template creates a Cocoa application for the OS X platform).

Enter the “Product Name” and choose the Swift Programming Language.

Go to the “Project Navigator” area and select the “Main.storyboard”.

Search for a “Label” in the Object Library:

Xcode, Object Library, Label

Figure: Xcode, Object Library

Drag & Drop a Label from the Library to the Window.

You can use the so called Inspector, located right above the Library, in order to change the name of the window and the name of the Label to “Hello World!”.

If you click on the window the Inspector will show the attributes of the window.

Xcode, Attributes Inspector, Window

Figure: Xcode, Inspector, attributes of a window

If you click on the label the Inspector will show the attributes of the label.

Xcode, Attributes Inspector, Label

Figure: Xcode, Inspector, attributes of a label

Xcode, Main.storyboard

Figure: Xcode, Main.storyboard

Run the application: Main Menu > Product > Run

The output is:

Xcode, Window, Hello World!

 

www.ece.nu