万本电子书0元读

万本电子书0元读

顶部广告

Mastering Swift 5电子书

售       价:¥

138人正在读 | 0人评论 6.2

作       者:Jon Hoffman

出  版  社:Packt Publishing

出版时间:2019-04-30

字       数:47.9万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:此类商品不支持退换货,不支持下载打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Harness the power of the latest edition with this in-depth and comprehensive guide to the Swift language Key Features * Fifth edition of this bestselling book, improved and updated to cover the latest version of the Swift 5 programming language * Get to grips with popular and modern design techniques to write easy-to-manage Swift code * Learn how to use core Swift features such as concurrency, generics, and copy-on-write in your code Book Description Over the years, the Mastering Swift book has established itself amongst developers as a popular choice as an in-depth and practical guide to the Swift programming language. The latest edition is fully updated and revised to cover the new version: Swift 5. Inside this book, you'll find the key features of Swift 5 easily explained with complete sets of examples. From the basics of the language to popular features such as concurrency, generics, and memory management, this definitive guide will help you develop your expertise and mastery of the Swift language. Mastering Swift 5, Fifth Edition will give you an in-depth knowledge of some of the most sophisticated elements in Swift development, including protocol extensions, error handling, and closures. It will guide you on how to use and apply them in your own projects. Later, you'll see how to leverage the power of protocol-oriented programming to write flexible and easier-to-manage code. You will also see how to add the copy-on-write feature to your custom value types and how to avoid memory management issues caused by strong reference cycles. What you will learn * Understand core Swift components, including operators, collections, control flows, and functions * Learn how and when to use classes, structures, and enumerations * Understand how to use protocol-oriented design with extensions to write easier-to-manage code * Use design patterns with Swift, to solve commonly occurring design problems * Implement copy-on-write for you custom value types to improve performance * Add concurrency to your applications using Grand Central Dispatch and Operation Queues * Implement generics to write flexible and reusable code Who this book is for This book is for developers who want to delve into the newest version of Swift. If you are a developer and learn best by looking at and working with code, then this book is for you. A basic understanding of Apple's tools would be beneficial but not mandatory. All examples should work on the Linux platform as well.
目录展开

About Packt

Why subscribe?

Contributors

About the author

About the reviewers

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Conventions used

Get in touch

Reviews

Taking the First Steps with Swift

What is Swift?

Swift features

Playgrounds

Getting started with playgrounds

iOS, tvOS, and macOS playgrounds

Showing images in a playground

Creating and displaying graphs in playgrounds

What playgrounds are not

Swift language syntax

Comments

Semicolons

Parentheses

Curly brackets

An assignment operator does not return a value

Spaces are optional in conditional and assignment statements

Hello World

Summary

Learning about Variables, Constants, Strings, and Operators

Constants and variables

Defining constants and variables

Type safety

Type inference

Explicit types

Numeric types

Integer types

Floating-point and Double values

The Boolean type

The String type

Tuples

Enumerations

Operators

Assignment operator

Comparison operators

Arithmetic operators

Remainder operator

Compound assignment operators

Closed range operator

Half open range operator

Ternary conditional operator

Logical NOT operator

Logical AND operator

Logical OR operator

Summary

Optional Types

Introducing optionals

The need for optional types in Swift

Defining an optional

Using optionals

Forced unwrapping of an optional

Optional binding

Optional types with tuples

Optional chaining

The nil coalescing operator

Summary

Using Swift Collections

Swift collection types

Mutability

Arrays

Creating and initializing arrays

Accessing the array element

Counting the elements of an array

Is the array empty?

Shuffling an array

Appending to an array

Inserting a value into an array

Replacing elements in an array

Removing elements from an array

Merging two arrays

Retrieving a subarray from an array

Making bulk changes to an array

Algorithms for arrays

Sort

Sorted

Filter

Map

Count

forEach

Iterating over an array

Dictionaries

Creating and initializing dictionaries

Accessing dictionary values

Counting the key or values in a dictionary

Is the dictionary empty?

Updating the value of a key

Adding a key-value pair

Removing a key-value pair

Set

Initializing a set

Inserting items into a set

Determining the number of items in a set

Checking whether a set contains an item

Iterating over a set

Removing items in a set

Set operations

Summary

Control Flow

What have we learned so far?

Curly brackets

Parentheses

Control flow

Conditional statements

The if statement

Conditional code execution with the if...else statement

The guard statement

The for-in loop

Using the for-in loop

The while loop

Using the while loop

Using the repeat-while loop

The switch statement

Switch on tuples

Match on wildcard

Using case and where statements with conditional statements

Filtering with the where statement

Filtering with the for-case statement

Using the if-case statement

Control transfer statements

The continue statement

The break statement

The fallthrough statement

Summary

Functions

Using a single parameter function

Using a multi-parameter function

Defining a parameter's default values

Returning multiple values from a function

Adding external parameter names

Using variadic parameters

Inout parameters

Omitting argument labels

Putting it all together

Summary

Classes, Structures, and Protocols

What are classes and structures?

Similarities between classes and structures

Differences between classes and structures

Value versus reference types

Creating a class or structure

Properties

Stored properties

Computed properties

Property observers

Methods

Custom initializers

Internal and external parameter names

Failable initializers

Access controls

Inheritance

Overriding methods and properties

Overriding methods

Overriding properties

Preventing overrides

Protocols

Protocol syntax

Property requirements

Method requirements

Extensions

Optional chaining

Summary

Using Protocols and Protocol Extensions

Protocols as types

Polymorphism with protocols

Type casting with protocols

Protocol extensions

Do I need to use protocols?

Swift's standard library

Summary

Protocol Oriented Design

Requirements

Object-oriented design

Protocol-oriented design

Protocol inheritance

Protocol composition

Protocol-oriented design

Using the where statement with protocols

Structures versus classes

The array structure

Summary

Generics

Introducing generics

Generic functions

Generic types

Conditionally adding extensions with generics

Conditional conformance

Generic subscripts

Associated types

Summary

Availability and Error Handling

Native error handling

Representing errors

Throwing errors

Catching errors

The availability attribute

Summary

Custom Subscripting

Introducing subscripts

Subscripts with Swift arrays

Creating and using custom subscripts

Read-only custom subscripts

Calculated subscripts

Subscript values

External names for subscripts

Multidimensional subscripts

Dynamic member lookup

When not to use a custom subscript

Summary

Working with Closures

An introduction to closures

Simple closures

Shorthand syntax for closures

Using closures with Swift's array algorithms

Changing functionality

Selecting a closure based on results

Summary

Concurrency and Parallelism in Swift

Concurrency and parallelism

Grand Central Dispatch

Calculation type

Creating queues

Creating and using a concurrent queue

Creating and using a serial queue

Async versus sync

Executing code on the main queue function

Using asyncAfter

Using the Operation and OperationQueue types

Using BlockOperation

Using the addOperation() method of the operation queue

Subclassing the Operation class

Summary

Custom Types

Value types and reference types

Recursive data types for reference types

Inheritance for reference types

Dynamic dispatch

Copy-on-write

Implementing the equatable protocol

Summary

Memory Management

How ARC works

Strong reference cycles

Summary

Swift Formatting and Style Guider

What is a programming style guide?

Your style guide

Do not use semicolons at the end of statements

Do not use parentheses for conditional statements

Naming

Custom types

Functions and methods

Constants and variables

Indenting

Comments

Using the self keyword

Constants and variables

Optional types

Using optional binding

Using optional chaining instead of optional binding for multiple unwrapping

Using type inference

Using shorthand declaration for collections

Using switch rather than multiple if statements

Don't leave commented-out code in your application

Summary

Adopting Design Patterns in Swift

What are design patterns?

Creational patterns

The singleton design pattern

Understanding the problem

Understanding the solution

Implementing the singleton pattern

The builder design pattern

Understanding the problem

Understanding the solution

Implementing the builder pattern

Structural design patterns

The bridge pattern

Understanding the problem

Understanding the solution

Implementing the bridge pattern

The facade pattern

Understanding the problem

Understanding the solution

Implementing the facade pattern

The proxy design pattern

Understanding the problem

Understanding the solution

Implementing the proxy pattern

Behavioral design patterns

The command design pattern

Understanding the problem

Understanding the solution

Implementing the command pattern

The strategy pattern

Understanding the problem

Understanding the solution

Implementing the strategy pattern

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部