Description
Enter the Swift future of iOS and OS X programming
Beginning Swift Programming is your ideal starting point for creating Mac, iPhone, and iPad apps using Apple's new Swift programming language. Written by an experienced Apple developer and trainer, this comprehensive guide explains everything you need to know to jumpstart the creation of your app idea. Coverage includes data types, strings and characters, operators and functions, arrays and dictionaries, control flow, and looping, with expert guidance on classes, objects, class inheritance, closures, protocols, and generics. This succinct — yet complete — overview provides a detailed introduction to the core features of Swift.
Apple developed Swift to address the limitations of Objective-C, and add features found in more complex languages like Python. The results is simpler, cleaner, more expressive code with automatic memory management, functional programming patterns, and more, including built-in features that make Swift apps faster, scalable, and more secure. This book explains it all, helping developers master Apple's new language.
- Become fluent with syntax that's easier to read and maintain
- Understand inferred types for cleaner, less mistake-prone code
- Learn the key features that make Swift more expressive than Objective-C
- Learn the new optional types in Swift that make your code more resilient
- Understand the key design patterns in iOS and Mac OS programming using protocols and delegates
- Learn how to use generics to create highly reusable code
- Learn the new access controls mechanism in Swift
Get up to speed quickly to remain relevant and ahead of the curve.
Chapter
CHAPTER 1: INTRODUCTION TO SWIFT
Setting Up the Environment
Creating a Playground Project
String Interpolation: Including Values in Strings
Floating-Point Operations
Implicitly Unwrapped Optionals
Unwrapping Optionals Using “?”
Using Enumeration in Switch Statements
Auto-Increment for Raw Values
CHAPTER 3: STRINGS AND CHARACTERS
Converting Strings to Arrays
Interoperability with NSString
Casting String to NSString
CHAPTER 4: BASIC OPERATORS
Increment and Decrement Operator
Compound Assignment Operators
Equal To and Not Equal To
Combining Logical Operators
Ternary Conditional Operator
Defi ning and Calling a Function
Returning Multiple Values
External Parameter Names Shorthand
Variadic (Variable) Parameters
Constant and Variable Parameters
Defining a Function Type Variable
Calling a Function Type Variable
Returning Function Type in a Function
Retrieving Elements from an Array
Inserting Elements into an Array
Modifying Elements in an Array
Appending Elements to an Array
Checking the Size of an Array
Removing Elements from an Array
Testing Arrays for Equality
Mutability of Dictionaries
Retrieving Elements from a Dictionary
Checking the Size of a Dictionary
Modifying an Item in the Dictionary
Removing an Item from the Dictionary
Iterating over a Dictionary
Creating an Empty Dictionary
Testing Dictionaries for Equality
Copying the Behavior of Arrays and Dictionaries
CHAPTER 7: CONTROL FLOW AND LOOPING
Matching a Range of Numbers
Control Transfer Statements
CHAPTER 8: STRUCTURES AND CLASSES
Structures as Value Types
Motivation Behind Computed Properties
Read-Only Computed Properties
Initializers and External Parameter Names
Initializing Variables and Constants During Initialization
Classes as Reference Types
Comparing Instances—Identity Operators
Comparing Instances—Equivalence Operators
Local and External Parameter Names for Methods
Understanding Inheritance
Instantiating a Base Class
Creating an Abstract Class
Inheriting from a Base Class
Creating Abstract Methods
Convenience Initializers and Initializer Chaining
Calling Initializers in Subclasses
Assigning Closures to Variables
Using the Array’s Three Closure Functions
Using Closures in Your Functions
CHAPTER 11: PROTOCOLS AND DELEGATES
Defining and Using a Protocol
Conforming to Multiple Protocols
Delegates as Event Handlers
A Practical Example of Protocols and Delegates
Specifying Type Constraint
Using Generics in Protocols
Specifying Requirements for Associated Types
APPENDIX: EXERCISE ANSWERS