1. Trang chủ
  2. » Công Nghệ Thông Tin

Swift Apprentice By Eli Ganim, Cosmin Pupăză, Matt Galloway, Ben Morrow, Alexis Gallagher and Ehab Yosry Amer

491 140 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • About the Cover

    • About the Authors

    • About the Editors

    • About the Artist

  • What You Need

  • Book License

  • Book Source Code & Forums

  • Introduction

    • Who this book is for

    • How to use this book

    • What’s in store

    • Acknowledgments

  • Chapter 1: Expressions, Variables & Constants

    • How a computer works

    • Playgrounds

    • Getting started with Swift

    • Printing out

    • Arithmetic operations

    • Math functions

    • Naming data

    • Increment and decrement

    • Challenges

    • Key points

  • Chapter 2: Types & Operations

    • Type conversion

    • Strings

    • Strings in Swift

    • Tuples

    • A whole lot of number types

    • Type aliases

    • A peek behind the curtains: Protocols

    • Challenges

    • Key points

  • Chapter 3: Basic Control Flow

    • Comparison operators

    • The if statement

    • Loops

    • Challenges

    • Key points

  • Chapter 4: Advanced Control Flow

    • Countable ranges

    • For loops

    • Switch statements

    • Challenges

    • Key points

  • Chapter 5: Functions

    • Function basics

    • Functions as variables

    • Commenting your functions

    • Challenges

    • Key points

  • Chapter 6: Optionals

    • Introducing nil

    • Introducing optionals

    • Unwrapping optionals

    • Introducing guard

    • Nil coalescing

    • Challenges

    • Key points

  • Chapter 7: Arrays, Dictionaries & Sets

    • Mutable versus immutable collections

    • Arrays

    • What is an array?

    • When are arrays useful?

    • Creating arrays

    • Accessing elements

    • Modifying arrays

    • Iterating through an array

    • Running time for array operations

    • Dictionaries

    • Creating dictionaries

    • Accessing values

    • Modifying dictionaries

    • Sets

    • Key points

    • Challenges

  • Chapter 8: Collection Iteration with Closures

    • Closure basics

    • Custom sorting with closures

    • Iterating over collections with closures

    • Challenges

    • Key points

  • Chapter 9: Strings

    • Strings as collections

    • Strings as bi-directional collections

    • Raw strings

    • Substrings

    • Character properties

    • Encoding

    • Challenges

    • Key points

  • Chapter 10: Structures

    • Introducing structures

    • Accessing members

    • Introducing methods

    • Structures as values

    • Structures everywhere

    • Conforming to a protocol

    • Challenges

    • Key points

  • Chapter 11: Properties

    • Stored properties

    • Computed properties

    • Type properties

    • Property observers

    • Lazy properties

    • Challenges

    • Key points

  • Chapter 12: Methods

    • Method refresher

    • Introducing self

    • Introducing initializers

    • Introducing mutating methods

    • Type methods

    • Adding to an existing structure with extensions

    • Challenges

    • Key points

  • Chapter 13: Classes

    • Creating classes

    • Reference types

    • Understanding state and side effects

    • Extending a class using an extension

    • When to use a class versus a struct

    • Challenges

    • Key points

  • Chapter 14: Advanced Classes

    • Introducing inheritance

    • Inheritance and class initialization

    • When and why to subclass

    • Understanding the class lifecycle

    • Challenges

    • Key points

  • Chapter 15: Enumerations

    • Your first enumeration

    • Raw values

    • Associated values

    • Enumeration as state machine

    • Iterating through all cases

    • Enumerations without any cases

    • Optionals

    • Challenges

    • Key points

  • Chapter 16: Protocols

    • Introducing protocols

    • Implementing protocols

    • Protocols in the Standard Library

    • Challenge

    • Key points

  • Chapter 17: Generics

    • Introducing generics

    • Anatomy of generic types

    • Arrays

    • Dictionaries

    • Optionals

    • Generic function parameters

    • Challenge

    • Key points

  • Chapter 18: Access Control, Code Organization and Testing

    • Introducing access control

    • Organizing code into extensions

    • Swift Package Manager

    • Testing

    • Challenges

    • Key points

  • Chapter 19: Custom Operators, Subscripts & Keypaths

    • Custom operators

    • Subscripts

    • Keypaths

    • Challenges

    • Key points

  • Chapter 20: Pattern Matching

    • Introducing patterns

    • Basic pattern matching

    • Patterns

    • Advanced patterns

    • Programming exercises

    • Expression pattern

    • Challenges

    • Key points

  • Chapter 21: Error Handling

    • What is error handling?

    • First level error handling with optionals

    • Error protocol

    • Throwing errors

    • Handling errors

    • Advanced error handling

    • Rethrows

    • Error handling for asynchronous code

    • Challenges

    • Key points

  • Chapter 22: Encoding & Decoding Types

    • Encodable and Decodable protocols

    • What is Codable?

    • Automatic encoding and decoding

    • Encoding and decoding custom types

    • Renaming properties with CodingKeys

    • Manual encoding and decoding

    • Writing tests for the Encoder and Decoder

    • Challenges

    • Key points

  • Chapter 23: Memory Management

    • Reference cycles for classes

    • Reference cycles for closures

    • Challenges

    • Key points

  • Chapter 24: Value Types & Value Semantics

    • Value types vs. reference types

    • Defining value semantics

    • Implementing value semantics

    • Recipes for value semantics

    • Challenges

    • Key points

    • Where to go from here?

  • Chapter 25: Protocol-Oriented Programming

    • Introducing protocol extensions

    • Default implementations

    • Understanding protocol extension dispatch

    • Type constraints

    • Protocol-oriented benefits

    • Why Swift is a protocol-oriented language

    • Challenges

    • Key points

  • Chapter 26: Advanced Protocols & Generics

    • Existential protocols

    • Non-existential protocols

    • Recursive protocols

    • Heterogeneous collections

    • Type erasure

    • Opaque return types

    • Challenges

    • Key points

  • Conclusion

Nội dung

Swift Apprentice By Eli Ganim, Cosmin Pupăză, Matt Galloway, Ben Morrow, Alexis Gallagher and Ehab Yosry Amer Beginning programming with Swift This book takes you from beginner to advanced in Swift: Apple’s modern programming language for iOS.

Swift Apprentice Swift Apprentice Ehab Amer, Alexis Gallagher, Matt Galloway, Eli Ganim, Ben Morrow and Cosmin Pupăză Copyright ©2019 Razeware LLC Notice of Rights All rights reserved No part of this book or corresponding materials (such as text, images, or source code) may be reproduced or distributed by any means without prior written permission of the copyright owner Notice of Liability This book and all corresponding materials (such as source code) are provided on an “as is” basis, without warranty of any kind, express of implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in action of contract, tort or otherwise, arising from, out of or in connection with the software or the use of other dealing in the software Trademarks All trademarks and registered trademarks appearing in this book are the property of their own respective owners raywenderlich.com Swift Apprentice Table of Contents: Overview About the Cover 14 What You Need 18 Book License 19 Book Source Code & Forums 20 Introduction 22 Section I: Swift Basics 26 Chapter 1: Expressions, Variables & Constants 28 Chapter 2: Types & Operations 56 Chapter 3: Basic Control Flow 75 Chapter 4: Advanced Control Flow 92 Chapter 5: Functions 108 Chapter 6: Optionals 126 Section II: Collection Types 140 Chapter 7: Arrays, Dictionaries & Sets 142 Chapter 8: Collection Iteration with Closures 168 Chapter 9: Strings 183 Section III: Building Your Own Types 202 Chapter 10: Structures 204 Chapter 11: Properties 216 Chapter 12: Methods 230 Chapter 13: Classes 247 raywenderlich.com Swift Apprentice Chapter 14: Advanced Classes 263 Chapter 15: Enumerations 285 Chapter 16: Protocols 302 Chapter 17: Generics 321 Section IV: Advanced Topics 335 Chapter 18: Access Control, Code Organization and Testing 337 Chapter 19: Custom Operators, Subscripts & Keypaths 359 Chapter 20: Pattern Matching 376 Chapter 21: Error Handling 396 Chapter 22: Encoding & Decoding Types 418 Chapter 23: Memory Management 430 Chapter 24: Value Types & Value Semantics 441 Chapter 25: Protocol-Oriented Programming 460 Chapter 26: Advanced Protocols & Generics 475 Conclusion 491 raywenderlich.com Swift Apprentice Table of Contents: Extended About the Cover 14 About the Authors 16 About the Editors 17 About the Artist 17 What You Need 18 Book License 19 Book Source Code & Forums 20 Introduction 22 Who this book is for How to use this book What’s in store Acknowledgments 23 23 23 24 Section I: Swift Basics 26 Chapter 1: Expressions, Variables & Constants 28 How a computer works Playgrounds Getting started with Swift Printing out Arithmetic operations Math functions Naming data Increment and decrement Challenges Key points 29 35 39 40 41 46 47 51 52 54 Chapter 2: Types & Operations 56 Type conversion 57 raywenderlich.com Swift Apprentice Strings Strings in Swift Tuples A whole lot of number types Type aliases A peek behind the curtains: Protocols Challenges Key points 61 63 67 69 70 71 72 74 Chapter 3: Basic Control Flow 75 Comparison operators The if statement Loops Challenges Key points 76 80 86 89 91 Chapter 4: Advanced Control Flow 92 Countable ranges 93 For loops 94 Switch statements 99 Challenges 105 Key points 107 Chapter 5: Functions 108 Function basics Functions as variables Commenting your functions Challenges Key points 109 117 120 122 125 Chapter 6: Optionals 126 Introducing nil 127 Introducing optionals 128 Unwrapping optionals 130 raywenderlich.com Swift Apprentice Introducing guard Nil coalescing Challenges Key points 134 136 137 139 Section II: Collection Types 140 Chapter 7: Arrays, Dictionaries & Sets 142 Mutable versus immutable collections Arrays What is an array? When are arrays useful? Creating arrays Accessing elements Modifying arrays Iterating through an array Running time for array operations Dictionaries Creating dictionaries Accessing values Modifying dictionaries Sets Key points Challenges 143 143 143 144 144 145 149 152 154 155 155 156 157 161 163 164 Chapter 8: Collection Iteration with Closures 168 Closure basics Custom sorting with closures Iterating over collections with closures Challenges Key points 169 174 174 180 182 Chapter 9: Strings 183 Strings as collections 184 raywenderlich.com Swift Apprentice Strings as bi-directional collections Raw strings Substrings Character properties Encoding Challenges Key points 189 190 190 192 193 199 200 Section III: Building Your Own Types 202 Chapter 10: Structures 204 Introducing structures Accessing members Introducing methods Structures as values Structures everywhere Conforming to a protocol Challenges Key points 205 209 210 211 212 213 214 215 Chapter 11: Properties 216 Stored properties Computed properties Type properties Property observers Lazy properties Challenges Key points 217 219 222 223 226 228 229 Chapter 12: Methods 230 Method refresher Introducing self Introducing initializers Introducing mutating methods raywenderlich.com 231 233 235 239 Swift Apprentice Type methods Adding to an existing structure with extensions Challenges Key points 240 242 244 246 Chapter 13: Classes 247 Creating classes Reference types Understanding state and side effects Extending a class using an extension When to use a class versus a struct Challenges Key points 248 249 257 258 259 260 262 Chapter 14: Advanced Classes 263 Introducing inheritance Inheritance and class initialization When and why to subclass Understanding the class lifecycle Challenges Key points 264 271 277 280 283 284 Chapter 15: Enumerations 285 Your first enumeration Raw values Associated values Enumeration as state machine Iterating through all cases Enumerations without any cases Optionals Challenges Key points 286 290 293 295 296 297 298 299 301 Chapter 16: Protocols 302 raywenderlich.com Swift Apprentice Introducing protocols Implementing protocols Protocols in the Standard Library Challenge Key points 303 308 314 319 319 Chapter 17: Generics 321 Introducing generics Anatomy of generic types Arrays Dictionaries Optionals Generic function parameters Challenge Key points 322 324 329 330 331 332 333 334 Section IV: Advanced Topics 335 Chapter 18: Access Control, Code Organization and Testing 337 Introducing access control Organizing code into extensions Swift Package Manager Testing Challenges Key points 339 348 352 352 356 358 Chapter 19: Custom Operators, Subscripts & Keypaths 359 Custom operators Subscripts Keypaths Challenges Key points raywenderlich.com 360 365 371 373 375 10 ... anywhere, at anytime raywenderlich. com 20 Swift Apprentice Book Source Code & Forums Visit our Swift Apprentice store page here: • https://store .raywenderlich. com/products /swift- apprentice And if... second and third editions of Swift Apprentice • Erik Kerber For his previous work on the first and second editions of Swift Apprentice raywenderlich. com 24 Swift Apprentice Introduction • Our... edition version of the book raywenderlich. com 21 I Introduction By Ray Fix Welcome to the Swift Apprentice, fully updated for Xcode 11 and Swift 5.1! In the last five years, Swift has gone from being

Ngày đăng: 17/05/2021, 07:52

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN