Beginning Swift
eBook - ePub

Beginning Swift

Master the fundamentals of programming in Swift 4

Rob Kerr, Kåre Morstøl

Share book
  1. 196 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Beginning Swift

Master the fundamentals of programming in Swift 4

Rob Kerr, Kåre Morstøl

Book details
Book preview
Table of contents
Citations

About This Book

Swift greatly simplifies the process of developing applications for Apple devices. This book provides you with the essential skills to help you get started with developing applications using Swift.

Key Features

  • 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

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

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

Who this book is 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.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Beginning Swift an online PDF/ePUB?
Yes, you can access Beginning Swift by Rob Kerr, Kåre Morstøl in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781789538649
Edition
1

Beginning Swift


Table of Contents

Beginning Swift
Why Subscribe?
PacktPub.com
Contributors
About the Authors
Packt is Searching for Authors Like You
Preface
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. Swift Basics
Lesson objectives
Swift Program Structure
Hello, World!
Swift Variables and Constants
Declaring Swift Variables
Variables Versus Constants
Type Inference
Variable Naming
Working with Variables
Tuples
Creating a Tuple
Optionals
Declaring an Optional
Working with Optionals
Optional nil Values
Accessing Optional Values
Force Unwrapping an Optional
Conditionally Unwrapping Optionals
Using Optionals
The Swift guard Statement
Activity: Variable Summary
Swift Data Types
Numeric Data Types
Int on 64-Bit Versus 32-Bit Platforms
Built-In Numeric Data Types
Choosing the Appropriate Numeric Data Type
Declaring and Assigning Integer Variables
Declaring and Assigning Floating Point Numbers
Numeric Literal Grouping
Numeric Type Conversions
Using Numeric Types
Boolean
Character
Assigning a Character
Constructing a Character Literal
String
Instantiating a String
String Concatenation
Extracting Characters
String Length
Activity: Data Type Summary
Enums
Basic Enum Syntax
Enum with Raw Values
Activity: Using Swift Enums
Summary
2. Swift Operators and Control Flow
Lesson objectives
Swift Operators
Assignment Operator
Arithmetic Operators
Standard Arithmetic Operators
Remainder Operator
Unary minus Operator
Compound Assignment Operators
Comparison Operators
Equality
Inequality
Comparison between Two Values
Ternary Conditional Operator
Logical Operators
Bitwise Operators
Nil-Coalescing Operator
Range Operators
Closed Range Operator
Half-Open Range Operator
One-Sided Range Operator
Activity: Operators
Branching
The if Statement
Condition Lists
Optional Unwrapping with if
The switch Statement
switch Statement Rules
The break Keyword
The fallthrough Keyword
Matching Non-Scalar Values
Multiple Patterns in a Single Case
Using the where Statement within case
Evaluating Optionals with a switch Statement
Activity: Converting Code from if to switch
Loops
The for…in Statement
Iterating over Objects
Iterating over Array Objects with index
The for Loop where Clause
The break Control Transfer Statement
The continue Control Transfer Statement
The while Loop
The repeat…while Loop
Activity: Implementing Loops
Summary
3. Functions, Classes, and Structs
Lesson Objectives
Functions
Defining a Function
Argument Labels
Excluding Argument Labels
Parameter Default Values
Activity: Implementing a Function
Returning Values from Functions
Using @discardableResult
Function Attributes
Variadic Parameters
inout Parameters
Recursion
Functions as Parameters
Closures
Creating a Function to Receive Content from an Asynchronous Web Service Call
Error Handling
The do…catch Statement
Multiple catch Blocks
Using do without catch
The guard Statement
Activity: Exception Handling
Object-Oriented Features
Object-Oriented Principles
Classes Versus Structs
Illustration
Defining Classes and Structures
Activity: Creating a Customer Struct and Class
Summary
Challenge
4. Collections
Lesson Objectives
Arrays
Working with Arrays
Index
Common Operations with Index
ArraySlice
Creating Slices
Activity: Working with Arrays
Sets
Working with Sets
Combining Sets
Comparing Sets
Activity: Removing Duplicates from a Sequence
Dictionaries
Working with Dictionaries
Activity: Using Dictionaries
Summary
5. Strings
Lesson Objectives
String Fundamentals
Character
Collection
Index
Working with String Index
Debugging
Activity: All Indices of a Character
Using Strings
Creating Strings
Common Operations
Activity: All Ranges of a Substring
Activity: Counting Words, Sentences, and Paragraphs
Substring
Creating Substrings
Parsing Strings
Converting NSRange to Range
Activity: CamelCase
Summary
6. Functional Programming and Lazy Operations
Lesson Objectives
Function Type
Functional Methods
filter
Using the filter Method
map
Using the map Method
flatMap
Using the flatMap Method
reduce
Using the reduce Function
Activity: Using Functional Programming
Lazy Operations
Lazy Sequences
Sequence Internals
Creating Lazy Operations
sequence(first:next:)
sequence(state:next:)
Activity: Implementing a Lazy Version of a Method
Swifty Code
Naming
Organizing Code
Miscellaneous
Writing Swifty Code
Summary
Further Study
Challenge
Index

Beginning Swift

Copyright © 2018 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 authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been 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 accurac...

Table of contents