Book Image

Swift 3 New Features

By : Keith Elliott
Book Image

Swift 3 New Features

By: Keith Elliott

Overview of this book

Since Swift was introduced by Apple in WWDC 2015, it has gone on to become one of the most beloved languages to develop iOS applications with. In the new version, the Swift team aimed to take its adoption to the next level by making it available for new platforms and audiences. This book will very quickly get you up to speed and productive with Swift 3. You will begin by understanding the process of submitting new feature requests for future versions of Swift. Swift 3 allows you to develop and run your applications on a Linux machine. Using this feature, you will write your first Linux application using the debugger in Linux. Using Swift migrator, you will initiate a conversion from Swift 2.2 to Swift 3. Further on, you will learn how to interact with Cocoa libraries when importing Objective C to Swift. You will explore the function and operator changes new to Swift 3, followed by Collection and Closure changes. You will also see the changes in Swift 3 that allow you write tests easier with XCTest and debug your running code better with new formats as well. Finally, you will have a running server written completely in Swift on a Linux box. By the end of the book, you will know everything you need to know to dive into Swift 3 and build successful projects.
Table of Contents (16 chapters)
Swift 3 New Features
About the Author
About the Reviewer
Function and Operator Changes – New Ways to Get Things Done

Importing code from Objective-C and C APIs to Swift 3

If you maintain Objective-C or C libraries and want to expose cleaner syntax for Swift, this section is for you! We now have the ability to provide more control over how constants, global functions, and generics are imported from Objective-C and C into Swift.

Importing Objective-C constants as Swift types [SE-0033]

Constants with global scope, defined in header files, are imported with the same global scope in Swift. In many cases, it would be more helpful to have related constants grouped together. In Swift 3, you can now annotate your type declarations with NS_STRING_ENUM or NS_EXTENSIBLE_STRING_ENUM to have those declarations imported as members of a common type.

Importing as Struct

If you want your constants to be imported as members of a struct, then add NS_EXTENSIBLE_STRING_ENUM to the end of your constant type declaration. For more consistent importing into Swift, name your constants using the same type as a prefix. In our example...