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
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Beginning Swift
Beginning Swift

Beginning Swift: Master the fundamentals of programming in Swift 4

Arrow left icon
Profile Icon Rob Kerr Profile Icon Kåre Morstøl
Arrow right icon
$14.99 $21.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (1 Ratings)
eBook May 2018 202 pages 1st Edition
eBook
$14.99 $21.99
Paperback
$26.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Rob Kerr Profile Icon Kåre Morstøl
Arrow right icon
$14.99 $21.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (1 Ratings)
eBook May 2018 202 pages 1st Edition
eBook
$14.99 $21.99
Paperback
$26.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$14.99 $21.99
Paperback
$26.99
Subscription
Free Trial
Renews at $19.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

Beginning Swift

Chapter 2. Swift Operators and Control Flow

In the last lesson, you learned the fundamentals of Swift syntax, data types, and how to use variables to store and operate on data in a Swift program.

In this lesson, you'll learn how to use the fundamental flow control structures and language elements that form the building blocks for Swift programs.

Swift contains a full set of flow control constructions that help you build logic and organize applications. Swift implements control structures you'll find familiar, and Swift adds modern features and extensions not available in some other languages.

This lesson also covers the broad range of Swift logical and bitwise operators. Swift supports a comprehensive set of operators, based on the C operator construction—but with modern extensions that we'll fully cover in this lesson.

Lesson objectives


By the end of this lesson, you will be able to do the following:

  • Use the assignment, arithmetic, and bitwise operators

  • Use Swift's comparison operators

  • Explain the functionality of Swift's range operators

  • Use the Swift branching features: if and switch

  • Control program flow with loops, such as for, while, and repeat/while

Swift Operators


Operators are special characters—usually drawn from mathematics—that are used to process evaluations, modify variable values, and combine values. Swift operators break down into categories by the function they perform:

  • Assignment operators

  • Arithmetic operators

  • Comparison operators

  • Logical operators

  • Bitwise operators

  • Nil-coalescing operators

  • Range operators

Refer to the following diagram:

Swift implements its assignment, arithmetic, comparison, logical, and bitwise operators nearly identically to other C-inspired languages, such as C++, Java, and C#—so your previous experience with these operators will apply directly to Swift programming.

In this lesson, we'll summarize this common set of operators, and only highlight unique Swift implementations. Should you need detailed information on the meaning of any of these operators, please refer to Apple's The Swift Programming Language guide ( https://developer.apple.com/library/content/documentation/Swift/Conceptual...

Branching


Flow control structures enable developers to apply logical processes and make decisions about what code is executed. Most modern programming languages provide a similar set of flow control structures:

  • The if statements execute code blocks when a Boolean condition is true.

  • The while loops execute blocks of code while a Boolean condition remains true.

  • The for loops execute blocks of code a specific number of times.

It's said that virtually any programming control flow requirement can be implemented with a while statement alone. However, the other various control structures allow programmers to create control flow that's more concise and clearly expresses the intent of the logical program flow.

Indeed, Swift provides a rich and powerful set of control structures, which you'll learn about in this section.

The if Statement

The most basic flow control statement in programming is the if statement, which executes a block of code if some Boolean expression...

Loops


After the branching structures if and switch, the most common structures you'll use in your programming are looping structures, which cause your program flow to execute the same code iteratively.

The looping structures you'll learn in this section are the following:

  • for…in, which executes the same code a predetermined number of times

  • while and repeat…while, which executes code until a true condition becomes false

As with the switch control structure, there are many features and flexible options provided by these structures that make Swift more expressive and powerful than many other programming languages.

The for…in Statement

The following diagram illustrates how the for...in statement works:

Most programming languages have a for statement used to execute a code statement a certain number of times. The preceding diagram illustrates how the for...in statement works. A canonical example of a for loop in C, similar to many other C-inspired languages, is the following: ...

Summary


In this lesson, you've learned how to use Swift's key language:

  • Assignment, arithmetic, and bitwise operators

  • Comparison and range operators

  • The Swift branching features: if and switch

  • Loops: for, while, repeat…while

You now have the skills needed to develop robust applications using Swift's powerful and expressive language syntax. In the next lesson, you'll learn the skills to develop functions and classes to organize your code. You will also explore and use error handling to efficiently handle unexpected errors in your programs.

Left arrow icon Right arrow icon

Key benefits

  • Teaches you how to correctly structure and architect software using Swift
  • Uses real-world examples to connect the theory to a professional setting
  • Imparts expertise in the core Swift standard library

Description

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.

Who is this book for?

If you are seeking fundamental Swift programming skills, in preparation for learning to develop native applications for iOS or macOS, this book is the best for you. You don’t need to have any prior Swift knowledge; however, object-oriented programming experience is desired.

What you will learn

  • Explore the fundamental Swift programming concepts, language structure, and the Swift programming syntax
  • Learn how Swift compares to other computer languages and how to transform your thinking to leverage new concepts such as optionals and protocols
  • Master how to use key language elements, such as strings and collections
  • Grasp how Swift supports modern application development using advanced features, such as built-in Unicode support and higher-order functions

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 31, 2018
Length: 202 pages
Edition : 1st
Language : English
ISBN-13 : 9781789538649
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 : May 31, 2018
Length: 202 pages
Edition : 1st
Language : English
ISBN-13 : 9781789538649
Vendor :
Apple
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 70.98
Learn Swift by Building Applications
$43.99
Beginning Swift
$26.99
Total $ 70.98 Stars icon

Table of Contents

6 Chapters
Swift Basics Chevron down icon Chevron up icon
Swift Operators and Control Flow Chevron down icon Chevron up icon
Functions, Classes, and Structs Chevron down icon Chevron up icon
Collections Chevron down icon Chevron up icon
Strings Chevron down icon Chevron up icon
Functional Programming and Lazy Operations Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(1 Ratings)
5 star 0%
4 star 100%
3 star 0%
2 star 0%
1 star 0%
Denis Edgar-Nevill Jun 07, 2019
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Lots of competing books
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.