Beginning Swift Programming
close menu
Bookswagon
search
My Account
Book 1
Book 2
Book 3
Book 1
Book 2
Book 3
Book 1
Book 2
Book 3
Book 1
Book 2
Book 3
Home > Computing and Information Technology Books > Computer programming / software engineering > Beginning Swift Programming
Beginning Swift Programming

Beginning Swift Programming


     0     
5
4
3
2
1



Out of Stock


Notify me when this book is in stock
X
About the Book

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.



Table of Contents:

INTRODUCTION xxiii

CHAPTER 1: INTRODUCTION TO SWIFT 1

What Is Swift? 2

Why Swift Is Important 3

Setting Up the Environment 3

Creating a Playground Project 4

Creating an iOS Project 6

Swift Syntax 10

Constants 10

Variables 12

String Interpolation: Including Values in Strings 14

Statements 14

Printing 15

Comments 15

Summary 17

CHAPTER 2: DATA TYPES 19

Basic Data Types 20

Integers 20

Types of Integers 21

Integer Operations 22

Integer Literals 22

Floating?]Point Numbers 23

Floating?]Point Operations 23

Floating?]Point Literals 24

Type Alias 25

Boolean 25

Tuples 26

Optional Types 27

Implicitly Unwrapped Optionals 28

Optional Binding 29

Unwrapping Optionals Using “?” 30

Enumerations 30

Using Enumeration in Switch Statements 31

Enumeration Raw Values 32

Auto?]Increment for Raw Values 33

Associated Values 34

Enumeration Functions 35

Summary 36

CHAPTER 3: STRINGS AND CHARACTERS 39

Strings 40

Mutability of Strings 40

Strings as Value Types 40

Characters 41

Concatenating Strings 43

Special Characters 44

Unicode 45

Common String Functions 46

Equality 46

Prefi x and Suffi x 47

Length 47

Substrings 48

Converting Strings to Arrays 51

Type Conversion 51

Interoperability with NSString 52

Casting String to NSString 53

Using NSString Directly 54

String or NSString? 55

Summary 56

CHAPTER 4: BASIC OPERATORS 59

Assignment Operator 60

Arithmetic Operators 61

Addition Operator 61

Subtraction Operator 62

Multiplication Operator 62

Division Operator 63

Modulus Operator 63

Increment and Decrement Operator 63

Compound Assignment Operators 65

Nil Coalescing Operator 65

Comparison Operators 66

Equal To and Not Equal To 66

Greater Than or Equal To 67

Less Than or Equal To 67

Range Operators 68

Logical Operators 69

NOT 69

AND 70

OR 71

Combining Logical Operators 71

Ternary Conditional Operator 72

Summary 73

CHAPTER 5: FUNCTIONS 75

Defi ning and Calling a Function 76

Input Parameters 76

Returning a Value 76

Returning Multiple Values 77

Function Parameter Names 77

External Parameter Names Shorthand 79

Default Parameter Values 79

Variadic (Variable) Parameters 80

Constant and Variable Parameters 81

In?]Out Parameters 82

Function Types 83

Defining a Function Type Variable 83

Calling a Function Type Variable 84

Returning Function Type in a Function 85

Nested Functions 85

Summary 86

CHAPTER 6: COLLECTIONS 89

Arrays 90

Mutability of Arrays 90

Array Data Types 90

Retrieving Elements from an Array 91

Inserting Elements into an Array 91

Modifying Elements in an Array 92

Appending Elements to an Array 92

Checking the Size of an Array 93

Removing Elements from an Array 93

Iterating over an Array 93

Creating an Empty Array 94

Testing Arrays for Equality 95

Dictionaries 96

Mutability of Dictionaries 97

Retrieving Elements from a Dictionary 97

Checking the Size of a Dictionary 98

Modifying an Item in the Dictionary 98

Removing an Item from the Dictionary 99

Iterating over a Dictionary 99

Creating an Empty Dictionary 101

Testing Dictionaries for Equality 101

Copying the Behavior of Arrays and Dictionaries 102

Summary 103

CHAPTER 7: CONTROL FLOW AND LOOPING 107

Flow Control 108

If Statement 108

If?]Else Statement 109

Switch Statement 110

Matching Numbers 111

Matching Characters 112

Fallthrough 112

Matching a Range of Numbers 113

Matching Tuples 114

Value Bindings 115

Where Clause 117

Looping 118

For?]In Loop 118

Traditional For Loop 121

While Loop 122

Do?]While Loop 123

Control Transfer Statements 124

Break Statement 124

Continue Statement 126

Labeled Statement 126

Summary 128

CHAPTER 8: STRUCTURES AND CLASSES 131

Structures 132

Memberwise Initializers 132

Structures as Value Types 133

Comparing Structures 135

Classes 135

Defining a Class 136

Properties 136

Stored Properties 136

Lazy Stored Properties 137

Computed Properties 138

Motivation Behind Computed Properties 139

The newValue keyword 140

Read?]Only Computed Properties 141

Property Observers 141

Typed Properties 143

Initializers 144

Initializers and External Parameter Names 145

Initializing Variables and Constants During Initialization 147

Classes as Reference Types 147

Comparing Instances—Identity Operators 149

Comparing Instances—Equivalence Operators 150

Methods in Classes 151

Instance Methods 151

Local and External Parameter Names for Methods 152

The self Property 154

Type Methods 155

Methods in Structures 155

Summary 157

CHAPTER 9: INHERITANCE 161

Understanding Inheritance 162

Defi ning a Base Class 162

Instantiating a Base Class 162

Creating an Abstract Class 163

Inheriting from a Base Class 164

Overriding Initializers 164

Overloading Initializers 165

Creating Abstract Methods 167

Overloading Methods 169

Preventing Subclassing 170

Types of Initializers 171

Default Initializer 171

Designated Initializers 172

Convenience Initializers and Initializer Chaining 174

Calling Initializers in Subclasses 176

Extensions 177

Extending Methods 177

Extending Properties 177

Access Controls 178

Internal 179

Private 180

Public 181

Summary 181

CHAPTER 10: CLOSURES 185

Understanding Closures 186

Functions as Closures 186

Assigning Closures to Variables 187

Writing Closures Inline 188

Type Inference 188

Shorthand Argument Names 189

Operator Function 190

Trailing Closures 190

Using the Array’s Three Closure Functions 190

The map Function 191

Example 1 191

Example 2 192

The filter Function 192

Example 1 192

Example 2 193

The reduce Function 194

Example 1 194

Example 2 195

Using Closures in Your Functions 196

Summary 198

CHAPTER 11: PROTOCOLS AND DELEGATES 201

Understanding Protocols 202

Defining and Using a Protocol 202

Conforming to a Protocol 202

Optional Methods 204

Conforming to Multiple Protocols 206

Property Requirements 206

Initializer Requirements 207

Understanding Delegates 207

Delegates as Event Handlers 208

A Practical Example of Protocols and Delegates 211

Summary 213

CHAPTER 12: GENERICS 217

Understanding Generics 218

Using Generic Functions 218

Multiple Type Parameters 219

Specifying Type Constraint 220

Generic Types 221

Generic Classes 221

Generic Structures 223

Generic Type Extension 224

Using Generics in Protocols 225

Specifying Requirements for Associated Types 228

Summary 229

APPENDIX: EXERCISE ANSWERS 233

INDEX 247



About the Author :

Wei-Meng Lee is a technologist and founder of Developer Learning Solutions (www.learn2develop.net), a technology company specializing in hands-on training on the latest mobile technologies. He is an established developer and trainer specializing in .NET, iOS, and Android.

Wei-Meng speaks regularly at international conferences and has authored and co-authored numerous books on .NET, XML, and mobile technologies. He writes extensively for the O’Reilly Network and Mobiforge.com on topics ranging from .NET to Mac OS X. He is also the author of Beginning iOS 5 Application Development and Beginning Android 4 Application Development, both from Wrox.


Best Sellers


Product Details
  • ISBN-13: 9781119042884
  • Publisher: John Wiley & Sons Inc
  • Publisher Imprint: Standards Information Network
  • Language: English
  • ISBN-10: 1119042887
  • Publisher Date: 04 Dec 2014
  • Binding: Digital (delivered electronically)
  • No of Pages: 288


Similar Products

Add Photo
Add Photo

Customer Reviews

REVIEWS      0     
Click Here To Be The First to Review this Product
Beginning Swift Programming
John Wiley & Sons Inc -
Beginning Swift Programming
Writing guidlines
We want to publish your review, so please:
  • keep your review on the product. Review's that defame author's character will be rejected.
  • Keep your review focused on the product.
  • Avoid writing about customer service. contact us instead if you have issue requiring immediate attention.
  • Refrain from mentioning competitors or the specific price you paid for the product.
  • Do not include any personally identifiable information, such as full names.

Beginning Swift Programming

Required fields are marked with *

Review Title*
Review
    Add Photo Add up to 6 photos
    Would you recommend this product to a friend?
    Tag this Book Read more
    Does your review contain spoilers?
    What type of reader best describes you?
    I agree to the terms & conditions
    You may receive emails regarding this submission. Any emails will include the ability to opt-out of future communications.

    CUSTOMER RATINGS AND REVIEWS AND QUESTIONS AND ANSWERS TERMS OF USE

    These Terms of Use govern your conduct associated with the Customer Ratings and Reviews and/or Questions and Answers service offered by Bookswagon (the "CRR Service").


    By submitting any content to Bookswagon, you guarantee that:
    • You are the sole author and owner of the intellectual property rights in the content;
    • All "moral rights" that you may have in such content have been voluntarily waived by you;
    • All content that you post is accurate;
    • You are at least 13 years old;
    • Use of the content you supply does not violate these Terms of Use and will not cause injury to any person or entity.
    You further agree that you may not submit any content:
    • That is known by you to be false, inaccurate or misleading;
    • That infringes any third party's copyright, patent, trademark, trade secret or other proprietary rights or rights of publicity or privacy;
    • That violates any law, statute, ordinance or regulation (including, but not limited to, those governing, consumer protection, unfair competition, anti-discrimination or false advertising);
    • That is, or may reasonably be considered to be, defamatory, libelous, hateful, racially or religiously biased or offensive, unlawfully threatening or unlawfully harassing to any individual, partnership or corporation;
    • For which you were compensated or granted any consideration by any unapproved third party;
    • That includes any information that references other websites, addresses, email addresses, contact information or phone numbers;
    • That contains any computer viruses, worms or other potentially damaging computer programs or files.
    You agree to indemnify and hold Bookswagon (and its officers, directors, agents, subsidiaries, joint ventures, employees and third-party service providers, including but not limited to Bazaarvoice, Inc.), harmless from all claims, demands, and damages (actual and consequential) of every kind and nature, known and unknown including reasonable attorneys' fees, arising out of a breach of your representations and warranties set forth above, or your violation of any law or the rights of a third party.


    For any content that you submit, you grant Bookswagon a perpetual, irrevocable, royalty-free, transferable right and license to use, copy, modify, delete in its entirety, adapt, publish, translate, create derivative works from and/or sell, transfer, and/or distribute such content and/or incorporate such content into any form, medium or technology throughout the world without compensation to you. Additionally,  Bookswagon may transfer or share any personal information that you submit with its third-party service providers, including but not limited to Bazaarvoice, Inc. in accordance with  Privacy Policy


    All content that you submit may be used at Bookswagon's sole discretion. Bookswagon reserves the right to change, condense, withhold publication, remove or delete any content on Bookswagon's website that Bookswagon deems, in its sole discretion, to violate the content guidelines or any other provision of these Terms of Use.  Bookswagon does not guarantee that you will have any recourse through Bookswagon to edit or delete any content you have submitted. Ratings and written comments are generally posted within two to four business days. However, Bookswagon reserves the right to remove or to refuse to post any submission to the extent authorized by law. You acknowledge that you, not Bookswagon, are responsible for the contents of your submission. None of the content that you submit shall be subject to any obligation of confidence on the part of Bookswagon, its agents, subsidiaries, affiliates, partners or third party service providers (including but not limited to Bazaarvoice, Inc.)and their respective directors, officers and employees.

    Accept


    Inspired by your browsing history


    Your review has been submitted!

    You've already reviewed this product!