Swift 3 New Features - Keith Elliott - E-Book

Swift 3 New Features E-Book

Keith Elliott

0,0
25,19 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

A fast-paced guide to get you up and running with Swift 3 and its new features

About This Book

  • Get up to date with the latest changes to Swift 3
  • Make your life easier by knowing how to port your Swift code to the latest version
  • Learn how to write programs that work on most of the major platforms such as iOS and Linux

Who This Book Is For

The book is for those who are familiar with Swift but are in need of clear guidance on what's changed in the latest version and the new features.

What You Will Learn

  • Migrate a Swift 2.2 project to Swift 3
  • Understand the workings of Swift Package Manager
  • Interact with Cocoa libraries when importing Objective C to Swift
  • Explore the function and operator changes new in Swift 3
  • Work with the advanced type changes, attribute improvements, and floating point type improvements in Swift
  • Discover the changes in the Swift API and see how Objective-C can be manipulated in the current API
  • Implement the new features central to Swift Testing and understand the new debug features
  • Create server-side applications using Swift 3

In Detail

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.

Style and approach

The book takes a tutorial-based approach offering an overview of the new features introduced in the latest version of Swift. It includes relevant examples of how code and concepts change when it comes to working on Swift 3 compared to previous versions.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 157

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Swift 3 New Features
Credits
About the Author
About the Reviewer
www.PacktPub.com
Why subscribe?
Preface
Objectives and achievements 
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. What Were They Thinking?
Apple's goals for Swift 3
Open source Swift
Contributing to Swift
Swift evolution process
Overview of accepted proposals for Swift 3
Summary
2. Discovering New Territories – Linux at Last!
Downloading Swift
Swift 3 on Mac
Swift 3 on Linux
Using the REPL
Swift Package Manager
Our first Swift program
Summary
3. Migrating to Swift 3 to Be More Swifty
How can you migrate your project…
Option1 - Migrating to Swift 3
Option 2 - Migrating to Swift 2.3
Planning ahead
Migrating with Xcode's Swift migration tool
Quick strategies for addressing issues
Summary
4. Changes to Swifts Core Will Have You Asking for More
The grand renaming
Referencing Objective-C code in Swift 3
Referencing the Objective-C selector of property getters and setters - SE-0064
Referencing Objective-C key paths [SE-0062]
Importing code from Objective-C and C APIs to Swift 3
Importing Objective-C constants as Swift types [SE-0033]
Importing as Struct
Importing as Enum
Importing Objective-C lightweight generics [SE-0057]
Importing as member [SE-0044]
Defining an initializer
Creating getters and setters
Adding methods
Creating static variables
Summary
5. Function and Operator Changes – New Ways to Get Things Done
Function declaration changes
Consistent parameter labeling [SE-0046]
Removing currying func syntax in declaration [SE0002]
Warning on Unused Results by Default [SE-0047]
Removing var from function parameter lists [SE-0003]
Removing ++ and -- operators [SE-0004]
Removing C-style for loops [SE-0007]
Removing implicit tuple splat from functions [SE-0029]
Adjusting inout declarations for type decoration [SE-0031]
Replacing equal signs with colons for attribute arguments [SE-0040]
Standardizing function type argument syntax to require parentheses [SE-0066]
Enforcing the order of defaulted parameters [SE-0060]
Making optional requirements Objective-C only [SE-0070]
Summary
6. Extra, Extra Collection and Closure Changes That Rock!
Collection and sequence type changes
Lazy FlatMap for sequence of optional [SE-0008]
Adding a first(where:) method to Sequence [SE-0032]
Add sequence(first: next:) and sequence(state: next:) [SE-0094]
A new model for collections and indices [SE-0065]
Introducing the Collection protocol
Conforming to the Collection protocol
New Range and associated indices types
Quick takeaways
Closure changes for Swift 3
Limiting inout Capture of @noescape Closures [SE-0035]
Resolution
Making non-escaping closures the default [SE-0103]
Summary
7. Hold onto Your Chair; Advanced Type Changes Are Here!
Unmanaged and UnsafePointer changes
Changing Unmanaged to use UnsafePointer [SE-0017]
Making UnsafePointer explicit using Optional [SE-0055]
Adding UnsafeRawPointer [SE-0107]
Type aliases and protocol changes
Generic type aliases [SE-0048]
Type aliases in protocols and protocol extensions [SE-0092]
Floating point changes
Enhanced Floating point protocols [SE-0067]
New rounding functions on the FloatingPoint protocol [SE-0113]
Summary
8. Oh Goodness! Look Whats New in the Foundation Framework
Mutability and Foundation value types
Value types versus reference types
Nested enumerations
Strongly typed string enumerations
Class properties
Type safe access with value types
Measurements and units
Measurement
Unit and dimension
Custom units
Custom Dimension types
Convert functions
Formatting measurements
Summary
9. Improving Your Code with Xcode Server and LLDB Debugging
Continuous integration overview with Xcode server
Bot features
Monitoring and managing bots
Configuring Xcode server
Adding repositories for the Xcode server
Configuring bots
Managing and monitoring your integration runs
Debugging with LLDB
LLDB command syntax
Managing breakpoints
Creating a breakpoint
Listing breakpoints
Modifying a breakpoint
Enabling and disabling a breakpoint
Deleting a breakpoint
Command aliases
Summary
10. Exploring Swift on the Server
IBM Swift Package catalog
Introducing our server project
Project description and dependencies
Setting up our environment and project
The Vapor framework
Routing
Creating views
Public resources
Defining our shop view
Slack integration
Making a custom integration
Updating our server to post to Slack
Summary

Swift 3 New Features

Swift 3 New Features

Copyright © 2016 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: October 2016

Production reference: 1041016

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham 

B3 2PB, UK.

ISBN 978-1-78646-963-2

www.packtpub.com

Credits

Author

Keith Elliott

Copy Editor

Charlotte Carneiro

Reviewer

Arthur Ariel Sabintsev

Project Coordinator

Sheejal Shah

Commissioning Editor

Ashwin Nair

Proofreader

Safis Editing

Acquisition Editor

Reshma Raman

Indexer

Tejal Daruwale Soni

Content Development Editor

Divij Kotian

Graphics

Jason Monteiro

Technical Editor

Gebin George

Production Coordinator

Aparna Bhagat

About the Author

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 wife’s 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.

I would like to thank my wife Grace, children Jadyn, Avery, Tobias, and Cohen, and his little dog Gideon for inspiring and helping me fulfill my dreams.

About the Reviewer

Arthur Ariel Sabintsev is one of the lead iOS engineers at The Washington Post. His mobile engineering career includes working for a U.S. Government-funded digital identity startup (ID.me), a Techstars funded video startup (Shelby.tv), and an award winning mobile development agency (Fueled).

He's also spent the last 3 years teaching Swift and Objective-C for General Assembly and writing over a dozen open source iOS libraries for the general public. Before leaving his PhD program, he was an experimental nuclear physicist who worked underground colliding subatomic and subnuclear particles.

www.PacktPub.com

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www.packtpub.com/mapt

Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

With the release of Swift 3, Apple is seeking to increase adoption of Swift. The mission of this book is to very quickly get new and seasoned developers up to speed and productive with Swift 3. We will explore the major features introduced to Foundation and the Standard Library. We will also provide commentary on how to convert existing Swift 2.2 projects to Swift 3 and examine Swift’s support for running and developing on Linux.

Objectives and achievements 

My objective is to introduce you to new concepts available with the release of Swift 3. Our journey together will hopefully lead you to a greater understanding in the following areas:

Understanding how the Grand Renaming will make your code easier to write and understand by other developersGetting comfortable with the tools available to write Swift applications on a Mac or on LinuxConverting your Swift 2.2 projects to Swift 3Making you aware of the syntax changes new to Swift 3

What this book covers

Chapter 1, What Were They Thinking?, introduces you to Swift 3. Swift is an important language for Apple and its adoption rate has been amazing so far. We will cover the process for how changes to the language are selected and how the community can contribute. In addition, we will cover Swift.org and Apple’s Github page as the repositories for everything that is happening in Swift.

Chapter 2, Discovering New Territories - Linux at Last!, discusses that, while Mac development was your only supported option up until recently, Swift 3 supports developing and running Swift applications on a Linux machine. Our goal is get your development environment setup on both a Mac and a Linux machine by the end of this chapter. We will write our first Linux application together.

Chapter 3, Migrating to Swift 3 to Be More Swifty, will show how to use the Swift Migrator to upgrade our Swift 2.2 projects.  We will use a sample project to walk through using the migrator and outline some useful strategies when migrating a Swift project.

Chapter 4, Changes to Swift's Core Will Have Asking for More, will quickly highlight the philosophies for writing good Swift APIs. Afterwards, we will spend the remaining chapter on language improvements for referencing and using Objective-C features in Swift 3 and importing code from Objective-C and C to Swift 3.

Chapter 5, Function and Operator Changes – New Ways to Get Things Done, will examine what's changed in function declaration and usage and how those changes translate into better Swift code. We will also explain operator changes and highlight several that have been removed from the language.

Chapter 6, Extra, Extra Collection and Closure Changes That Rock!, here we are focusing on collection and closure changes in Swift 3. There are several nice additions that will make working with collections even more fun. We will also explore some of the confusing side effects of creating closures in Swift 2.2 and how those have been fixed in Swift 3.

Chapter 7, Hold onto Your Chair, Advanced Type Changes are Here!, We are going to cover a few improvements to the language that you might not use on a regular basis. This chapter focuses on UnsafePointer types, typealiases, and floating point operations.

Chapter 8, Oh Goodness! Look What is New in the Foundation Framework, we will discuss the new Measurements and Units API. We will use several examples to hammer in the concepts so that you will leave this chapter better prepared to handle your measurement challenges in the future.

Chapter 9, Improving Your Code with Xcode Server and LLDB Debugging, we will cover Xcode Server’s capabilities as a continuous integration server and how automated testing can be included to improve your testing workflow. In the second half, we will describe how to use LLDB for debugging your code on Linux.

Chapter 10, Exploring Swift on the Server, shows that Swift running on Linux is a big deal, especially with Linux’s popularity for hosting and running servers. Swift 3 opens the possibilities for developers to create server-side applications using the same Swift that they use to create applications on iOS, macOS, tvOS, and watchOS. By the end of this chapter, you will have a running server written completely in Swift on a Linux box.

What you need for this book

This book will guide you through the installation of all the tools that you need to follow the examples. You will need to install Webstorm version 10 to effectively run the code samples present in this book.

Who this book is for

To develop in Swift 3 on a Mac, you will need Xcode 8 and macOS Sierra 10.12.  If you would like to take advantage of Swift on Linux, you need access to a Linux machine or virtual machine capable of running Ubuntu 14.04. 

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Swift-3-New-Features. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.

Chapter 1. What Were They Thinking?

Apple's release of Swift was a smashing hit from the very beginning. The language generated a lot of hype and it delivered. Of course, with the introduction of any new programming language, problems and issues will come along for the ride. Apple has carefully cultivated the young language, and has been steadily improving its base and introducing new features, support, and compatibility with its long mainstay incumbent, Objective-C. So, why would Apple open-source the language? What is Apple's objective and what does that tell us about the forthcoming release of Swift 3?

The focus of this chapter is to discuss Apple's goals for Swift 3, to show you where you can find the source of official information about new and current development in the language, and to explain how the community of developers will shape the fate of Swift as a language.

Apple's goals for Swift 3

During the What's New In Swift lecture from Apple's World Wide Developer Conference (WWDC) 2016, Apple engineers outlined several goals for the upcoming release of Swift 3:

Develop an open communityPortability to new platformsGet the fundamentals rightOptimize for awesomeness

Note

If you missed the conference, you can watch a replay of the talk on Apple's developer portal. Here's the link for What's New In Swift: https://developer.apple.com/videos/play/wwdc2016/42.