First steps, setting up before the start.
Is the language Apple introduced back in 2014 for the development of iOS and macOS applications, it adopts modern patterns, paradigms and is safer by design with strict rules minimizing the risk of undefined behaviors at runtime.
The language is expressive with its modern yet clean syntax in a way that it feels natural to write and a joy to read, which is awesome for collaborating and maintaining projects.
Xcode is Apple’s integrated development environment which consists of a suite of tools that developers use to build apps for Apple platforms.
Xcode manages the entire development workflow.
Xcode can be downloaded and installed directly from App Store
After the first launch you have to agree to the Xcode and iOS SDK license agreement.
After that we can start by exploring Xcode's Playgrounds.
Playgrounds provide an interactive environment in which we can evaluate and run Swift code without having a complete project, to begin exploring the language and learning the basics playgrounds are enough and quite convenient since code gets evaluated on the fly and overall is a lightweight environment.
Although is convenient to use playgrounds is always better to use and get familiar with Xcode as soon as posible because with having full exposure to the IDE is the only way to learn and get the best of its features.
The contents of the playground will differ for iOS and macOS as the framework is different, for iOS we have UIKit and for macOS Cocoa.
In this case we are not even using an API from those frameworks as there's only a string variable str declared and initialized. On the right sidebar of the playground is possible to see the evaluation of the statement displaying "Hello, playground"
In order to have some output, the following we can print to the console
The contents of the playground:
import Cocoa //macOS import UIKit //iOS var str = "Hello, playground" //String print(str)
After we run the playground, is possible to see the output in the terminal