It is essential for programmers to know the basics of Swift programming along with its environment setup and the procedure to install and way of writing codes. Swift provides a suitable platform for putting the Swift code and executes it. Now you will set up the same for learning purpose. In his chapter, you will learn about how to set up your programming environment as well as the basics of Swift language.
Setup the Local Environment
You need Xcode software to start your Swift coding. As you will get familiar with the swift coding concept of Swift, you can use the IDE (Xcode) for IOS and OS x application development. To start with this, you already need to have an account at Apple developer Website. The next steps are:
- Log in to Apple's Developer's Website.
- Once you are logged in, visit the link: https://developer.apple.com/download/
- It will show you a list of software available.
- Now, programmers need to install Xcode on their machine. After accepting the terms and conditions, open Xcode from the application folder.
- Now, you will get the get started with playground option.
- Enter the playground name along with the platform name (select IOS).
- Finally, you will get the Playground window.
Online Option for Programming
Programmers can also use the online facilities for online compilers to write, compile, and execute code for Swift. It will give confidence along with the flexibility to write code without installing compilers in the local computers. Some of them are:
Some other websites also offer the facility of online swift compilation and execution.
First Swift Program
var str = "Hello World!"
In the above code, import Cocoa statement makes all Cocoa libraries and APIs along with runtimes that outline the development layer for all of OS x, available in Swift. The above library is implemented in Objective-C (superset for C language).