Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering Swift 3
Mastering Swift 3

Mastering Swift 3: Build incredible apps for iOS and OS X

eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering Swift 3

Chapter 2. Learning About Variables, Constants, Strings, and Operators

The first program I ever wrote was written in the BASIC programming language and was the typical Hello World application. This application was pretty exciting at first, but the excitement of printing static text wore off pretty quickly. For my second application, I used BASIC's input command to prompt the user for a name and then printed out a custom hello message to the user with their name in it. At the age of 12, it was pretty cool to display Hello Han Solo. This application led me to create numerous Mad Lib style applications that prompted the user for various words and then put those words into a story that was displayed after the user had entered all the required words. These applications introduced me to, and taught me, the importance of variables. Every useful application I created since then has used variables.

In this chapter, we will cover the following topics:

  • What variables and constants...

Constants and variables

Constants and variables associate an identifier (such as myName or currentTemperature) with a value of a particular type (such as String or Int), where the identifier can be used to retrieve the value. The difference between a constant and a variable is that a variable can be updated or changed, while a constant cannot be changed once a value is assigned to it.

Constants are good for defining the values that you know will never change, such as the temperature that water freezes at or the speed of light. Constants are also good for defining a value that we use many times throughout our application, such as a standard font size or the maximum number of characters in a buffer. There will be numerous examples of constants throughout this book, and it is recommended that we use constants rather than variables whenever possible.

Variables tend to be more common in software development than constants. This is mainly because developers tend to prefer variables to constants...

Operators

An operator is a symbol or combination of symbols that we can use to check, change, or combine values. We have used operators in most of the examples so far in this book , but we did not specifically call them operators. In this section, we will show how to use most of the basic operators that Swift supports.

Swift supports most standard C operators and also improves them to eliminate several common coding errors. For example, the assignment operator does not return a value, which prevents it from being used where we meant to use the equality operator (==).

Let's look at the operators in Swift.

The assignment operator

The assignment operator initializes or updates a variable.

Prototype:

varA = varB 

Example:

let x = 1 
var y = "Hello" 
a = b 

Comparison operators

The comparison operator returns a Boolean true if the statement is true or a Boolean false if the statement is not true.

Prototypes:

Equality:  varA == varB 
Not equal:  varA != varB 
Greater than:  varA > varB...

Summary

In this chapter, we covered a lot of different topics. These topics ranged from variables and constants to data types and operators. The items in this chapter will be the foundation of every application that you write; therefore, it is important to understand the concepts discussed here.

In the next chapter, we will look at how we can use Swift collection types to store related data. These collection types are the dictionary and array types. We will also look at how we can use the Cocoa and Foundation data types in Swift.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • Discover the new features and improvements to Swift 3
  • • Get to grips with advanced design patterns and techniques to write smarter, cleaner Swift code
  • • Become a more fluent Swift developer and build powerful, impressive iOS and OS X applications.

Description

Swift is the definitive language of Apple development today. It’s a vital part of any iOS and OS X developer’s skillset, helping them to build the most impressive and popular apps on the App Store—the sort of apps that are essential to iPhone and iPad users every day. With version 3.0, the Swift team have added new features to improve the development experience—making it easier to get the results you want and customers expect. Inside, you’ll find the key features of Swift 3.0 and quickly learn how to use the newest updates to your development advantage. From Objective-C interoperability to ARC, to closures and concurrency, this advanced Swift guide will develop your expertise and make you more fluent in this vital programming language. We give you in-depth knowledge of some of the most sophisticated elements of Swift development including protocol extensions, error-handling, design patterns, and concurrency, and guide you on how to use and apply them in your own projects. You'll see how even the most challenging design patterns and programming techniques can be used to write cleaner code and to build more performant iOS and OS X applications. By the end of this book, you’ll have a handle on effective design patterns and techniques, which means you’ll soon be writing better iOS and OS X applications with a new level of sophistication and control.

Who is this book for?

This book is for developers who want to dive into the newest version of Swift. If you are a developer that learns best by looking at, and working with code, then this book is for you. A basic understanding of Apple's tools is beneficial but not mandatory.

What you will learn

  • Dive into the core components of Swift 3.0, including operators, collections, control flow, and functions
  • Create and use classes, structures, and enums
  • Understand object-oriented Swift and see how to tackle inheritance, protocols, and extensions
  • Develop a practical understanding of subscripts, optionals, and closures
  • See how to use the new protocol extension and error handling features of Swift 3.0
  • Add concurrency to your applications using Grand Central Dispatch

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 25, 2016
Length: 392 pages
Edition : 1st
Language : English
ISBN-13 : 9781786468635
Vendor :
Apple
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 25, 2016
Length: 392 pages
Edition : 1st
Language : English
ISBN-13 : 9781786468635
Vendor :
Apple
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 78.98
Mastering Swift 3
€36.99
Learning Xcode 8
€41.99
Total 78.98 Stars icon
Banner background image

Table of Contents

17 Chapters
1. Taking the First Steps with Swift Chevron down icon Chevron up icon
2. Learning About Variables, Constants, Strings, and Operators Chevron down icon Chevron up icon
3. Using Swift Collections and the Tuple Type Chevron down icon Chevron up icon
4. Control Flow and Functions Chevron down icon Chevron up icon
5. Classes and Structures Chevron down icon Chevron up icon
6. Using Protocols and Protocol Extensions Chevron down icon Chevron up icon
7. Protocol-Oriented Design Chevron down icon Chevron up icon
8. Writing Safer Code with Availability and Error Handling Chevron down icon Chevron up icon
9. Custom Subscripting Chevron down icon Chevron up icon
10. Using Optional Types Chevron down icon Chevron up icon
11. Working with Generics Chevron down icon Chevron up icon
12. Working with Closures Chevron down icon Chevron up icon
13. Using Mix and Match Chevron down icon Chevron up icon
14. Concurrency and Parallelism in Swift Chevron down icon Chevron up icon
15. Swift Formatting and Style Guide Chevron down icon Chevron up icon
16. Swifts Core Libraries Chevron down icon Chevron up icon
17. Adopting Design Patterns in Swift Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(8 Ratings)
5 star 75%
4 star 0%
3 star 12.5%
2 star 0%
1 star 12.5%
Filter icon Filter
Top Reviews

Filter reviews by




j4nnis Jan 18, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I was the technical reviewer for this book. This means I had a minor role in the production of this book. But it also means that i did read earlier drafts of this book fairly thoroughly. I can't very well give a comment on typos because I did not read the final version of every chapter. So my short review:The book gives a good introduction to Swift in it’s most current iteration. It explains critical concepts of the language like optionals, generics and closures without over-complicating them. Being a book specifically on Swift 3 it points out differences between earlier version of the language and this most current one. Jon’s style of writing is easy to follow and understand.I especially liked that the book does a detour and suggest how a few common design patterns could sensibly be adopted in Swift 3. For programmers coming from other languages this can be valuable as it shows familiar functionality done with a new set of tools.Although Swift 3 does not contain any language level concurrency Mastering Swift 3 explains existing technologies to deal with asynchronous problems. This includes an introduction to Grand Central Dispatch and Operation queues.I think the book does a good job of giving the reader an intoduction to Swift and to real world programming in this language.
Amazon Verified review Amazon
Dharma Kshetri Jan 20, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
lots of real-world examples and useful resources for learning swift3. I would like to highly recommended to all of developers, who want to learn swift 3.
Amazon Verified review Amazon
JMcDivitt Jan 14, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great Resource and learning material
Amazon Verified review Amazon
Sandeep Mahajan Apr 23, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Awesome book.
Amazon Verified review Amazon
Matthew Whillock Mar 27, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very good book, seems to cover everything in a readable style.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.