Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn SwiftUI

You're reading from   Learn SwiftUI An introductory guide to creating intuitive cross-platform user interfaces using Swift 5

Arrow left icon
Product type Paperback
Published in Apr 2020
Publisher Packt
ISBN-13 9781839215421
Length 316 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Chris Barker Chris Barker
Author Profile Icon Chris Barker
Chris Barker
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Getting Started with SwiftUI 2. Understanding Declarative Syntax FREE CHAPTER 3. Building Layout and Structure 4. Creating Your First Application 5. Understanding Controls, Views, and Lists 6. Working with Navigation in SwiftUI 7. Creating a Form with States and Data Binding 8. Networking and Linking to Your Existing App Logic 9. Maps and Location Services 10. Updating for iPad with NavigationViewStyle 11. SwiftUI on watchOS 12. SwiftUI versus UIKit 13. Basic Animation in Views 14. Animations in Transitions 15. Testing in SwiftUI 16. Other Books You May Enjoy

Introducing Swift as a programming language

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.

Apple had actually been developing Swift since 2010, a project originally started by Chris Lattner, who joined Apple in 2005 to work on the Low-Level Virtual Machine (LLVM) toolchain project.

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.

Open source software—Software that is created and distributed by developers under specific licenses, such as Apache 2.0 GNU General Public License (GPL) and Massachusetts Institute of Technology (MIT). The different flavors of licenses determine how developers can use and distribute the software.

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.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime