Reader small image

You're reading from  Swift 3 New Features

Product typeBook
Published inOct 2016
Reading LevelIntermediate
PublisherPackt
ISBN-139781786469632
Edition1st Edition
Languages
Right arrow
Author (1)
Keith Elliott
Keith Elliott
author image
Keith Elliott

Keith Elliott is a multitalented professional with unique business and technology experience spanning telecommunications, real estate investment banking, and capital markets. His work is driven simply by problems that need solutions, whether the problem is as simple as his wifes request for a custom to-do list or as complex as interest rate derivatives and foreign exchange hedging. He graduated with an MBA from Columbia Business School with an emphasis in entrepreneurship and an undergraduate degree from Georgia Institute of Technology with a bachelor's in computer engineering. Keith's own company, GittieLabs LLC, works with startups to provide technology solutions. His vision is to equip students with the real-life experience necessary to succeed in startup and corporate life. You can find his blog on the GittieLabs LLC website, www.gittie.com. On nights and weekends, Keith can be found spending time with his family, riding motorcycles with his lovely wife, watching football, and rewatching countless hours of WWDC videos.
Read more about Keith Elliott

Right arrow

Chapter 4. Changes to Swifts Core Will Have You Asking for More

Many of the libraries have been touched to pull off this effort including-the Swift standard library, all of Cocoa and Cocoa Touch frameworks, Core Graphics, and Grand Central Dispatch. With the release of Swift 3, we can expect changes that reduce the awkwardness of the language's link to Objective-C, exuding way more Swifty-ness. The Swift team has introduced new API guidelines with the intention of giving the language its own character. The result is a huge renaming and refactoring effort that flows throughout the language. Swift 3 has undergone a huge facelift in terms of its interaction with Objective-C and C APIs. The Swift team is aiming to make your development experience feel more like Swift and less like directly dumping Objective-C into your code. Swift is its own language and should have its own feel just like any other programming language. Yet prior versions of Swift were heavily influenced by the need to interact...

The grand renaming


Let's start with the proposals for the Swift API Design Guidelines. The Grand Renaming proposals represent, collectively, a very large undertaking and are covered by proposals SE-0005, SE-0006, SE-0086, and SE-0088. Implementing the API guidelines represents the largest change to the language for Swift 3. I couldn't possibly cover every API change resulting in the Grand Renaming proposals in this short book. Thankfully, you don't have to understand every line that changed in the libraries to be productive with Swift 3. You have two fantastic resources that will pay dividends with very little effort on your part. The first resource is the Swift migration tool which converts existing Swift projects to the latest syntax. When you use the Swift migrator, you can convert your Swift 2.2 projects to Swift 3 and receive most of the changes for free. The second extremely valuable resource is the Swift API Guidelines, which were developed to help make your code more Swifty. The...

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...

Summary


We just finished covering the principles of Swift's API Guidelines. In addition, I provided you with resources on how to find the Swift Evolution proposals that document the motivations for each change. We also covered new features to work with #selector and #keyPath expressions when working with Objective-C APIs in Swift. Finally, we explored working with C APIs and controlling how they are imported into Swift 3. In the next chapter, we will cover more language changes. Stay tuned as we still a have a lot of new things to cover!

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Swift 3 New Features
Published in: Oct 2016Publisher: PacktISBN-13: 9781786469632
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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Keith Elliott

Keith Elliott is a multitalented professional with unique business and technology experience spanning telecommunications, real estate investment banking, and capital markets. His work is driven simply by problems that need solutions, whether the problem is as simple as his wifes request for a custom to-do list or as complex as interest rate derivatives and foreign exchange hedging. He graduated with an MBA from Columbia Business School with an emphasis in entrepreneurship and an undergraduate degree from Georgia Institute of Technology with a bachelor's in computer engineering. Keith's own company, GittieLabs LLC, works with startups to provide technology solutions. His vision is to equip students with the real-life experience necessary to succeed in startup and corporate life. You can find his blog on the GittieLabs LLC website, www.gittie.com. On nights and weekends, Keith can be found spending time with his family, riding motorcycles with his lovely wife, watching football, and rewatching countless hours of WWDC videos.
Read more about Keith Elliott