Book Image

Beginning Swift

By : Rob Kerr, Kåre Morstøl
Book Image

Beginning Swift

By: Rob Kerr, Kåre Morstøl

Overview of this book

Take your first foray into programming for Apple devices with Swift.Swift is fundamentally different from Objective-C, as it is a protocol-oriented language. While you can still write normal object-oriented code in Swift, it requires a new way of thinking to take advantage of its powerful features and a solid understanding of the basics to become productive.
Table of Contents (10 chapters)

Error Handling


We ended the last section by examining some sample code after it had been made production-quality by adding correct error handling techniques. In this section, we'll dig into the most common Swift error handling techniques, which will help ensure all the code you develop in Swift will be robust and of high quality.

Swift supports many of the same error handling techniques available in other object-oriented languages, such as C++, Java, and C#. Functions—either your own or standard library functions—often return error codes as integers, error types, and Boolean variables. In addition, Swift provides exception handling using the do…catch construction, which is functionally equivalent to the try…catch construction used in many other languages.

The do…catch Statement

Most modern languages have exception handling features that allow code to throw exceptions from an inner scope that can be caught in an outer scope. In Swift, this pattern is implemented using the...