Whether you're a seasoned Mac/iOS developer or brand new to the scene, one way or another you'll have heard of Swift. The Swift programming language was first announced by Apple at the Apple Worldwide Developers Conference (WWDC) in 2014 and was intended to bring to the table numerous features from a multitude of other programming languages. Although not labeled as a successor, some feel that Swift was brought in to replace Apple's currently used programming language, Objective-C.
Since its announcement in 2014, Swift has taken on many iterations, with the current release at the time of writing being version 5.1.
However, the first major milestone for Swift came just after the announcement of version 2 at WWDC 2015, when Apple announced that version 2.2 was being open-sourced in December of that year. This decision was met with great enthusiasm by the community, with the ability to build, modify, and contribute to the Swift programming language. This kick-started many projects, including server-side Swift.
As mentioned previously, Swift was created with the idea of taking the best bits of other programming languages and rolling them into one.
Swift is known for providing benefits, such as being a type-safe language and its functional programming properties. For current macOS/iOS developers, one of the benefits of Swift is its ability to bridge and be used in conjunction with Objective-C, the benefit being that both languages use the LLVM compiler. The following screenshot shows an example of the type interface in Swift. As you can see, from line 4, there is no declaration of the type String; it is simply inferred by the value given:
Another big win for Swift is that it allows developers to write safe code. If written correctly and by implementing the correct safeguards made available in Swift, a developer shouldn't have to worry about their application ever throwing errors. Safeguarding in Swift lets you validate against objects that could be nil, with a very simple and easy-to-read syntax, which can be seen in the following example:
If you take a look at line 18 in the preceding screenshot, you'll see that we check variableString to see if it's not nil—if so, then it's assigned to the newString constant and is now safely available for use within the if statement.
In this section, we learned about the history of the Swift programming language and some of its core features. Next, we'll learn about existing user interface (UI) frameworks made available to us in Swift.