万本电子书0元读

万本电子书0元读

顶部广告

Hands-On Design Patterns with Swift电子书

售       价:¥

2人正在读 | 0人评论 9.8

作       者:Florent Vilmart

出  版  社:Packt Publishing

出版时间:2018-12-24

字       数:47.7万

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

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
From learning about the most sought-after design patterns to a comprehensive coverage of architectural patterns and code testing, this book is all you need to write clean, reusable code Key Features *Write clean, reusable and maintainable code, and make the most of the latest Swift version. *Analyze case studies of some of the popular open source projects and give your workflow a huge boost *Choose patterns such as MVP, MVC, and MVVM depending on the application being built Book Description Swift keeps gaining traction not only amongst Apple developers but also as a server-side language. This book demonstrates how to apply design patterns and best practices in real-life situations, whether that's for new or already existing projects. You’ll begin with a quick refresher on Swift, the compiler, the standard library, and the foundation, followed by the Cocoa design patterns – the ones at the core of many cocoa libraries – to follow up with the creational, structural, and behavioral patterns as defined by the GoF. You'll get acquainted with application architecture, as well as the most popular architectural design patterns, such as MVC and MVVM, and learn to use them in the context of Swift. In addition, you’ll walk through dependency injection and functional reactive programming. Special emphasis will be given to techniques to handle concurrency, including callbacks, futures and promises, and reactive programming. These techniques will help you adopt a test-driven approach to your workflow in order to use Swift Package Manager and integrate the framework into the original code base, along with Unit and UI testing. By the end of the book, you'll be able to build applications that are scalable, faster, and easier to maintain. What you will learn *Work efficiently with Foundation and Swift Standard library *Understand the most critical GoF patterns and use them efficiently *Use Swift 4.2 and its unique capabilities (and limitations) to implement and improve GoF patterns *Improve your application architecture and optimize for maintainability and performance *Write efficient and clean concurrent programs using futures and promises, or reactive programming techniques *Use Swift Package Manager to refactor your program into reusable components *Leverage testing and other techniques for writing robust code Who this book is for This book is for intermediate developers who want to apply design patterns with Swift to structure and scale their applications. You are expected to have basic knowledge of iOS and Swift.
目录展开

Title Page

Copyright and Credits

Hands-On Design Patterns with Swift

About Packt

Why subscribe?

Packt.com

Contributors

About the authors

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

Download the color images

Conventions used

Get in touch

Reviews

Refreshing the Basics

Classes and structs

Classes

Struct

Enums

Simple enums

Adding methods

Associating values

Generic enums

Raw type enums

Switching the state of light

Closures, functions, and currying

Currying

Using closures as callbacks

Using weak and unowned

Protocols

Declaring a protocol

Conforming to a protocol

Conformance at declaration

Conformance in an extension

Protocol extensions

Default implementations

Tuples, type aliases, and generics

Tuples

Declaring tuples

Destructuring tuples

Using tuples in functions

Type aliases

Generics

Generic functions

Generic types

Generics, protocols, and associated types

Summary

Understanding ARC and Memory Management

A brief history of reference counting

The semantics of reference counting

Retain

Release

Assign

Copying

Using and misusing manual reference counting

Memory leaks

Dangling pointers

ARC – what is that?

Value types

Strong references

Weak references

Unowned references

Memory debugging

Configuring your project

Using the memory graph hierarchy tool

Leaks, cycles, and dangling references

Leaking with cycles

A simple leak

Fixing the leak

Using weak

Using unowned

Dangling references

Summary

Diving into Foundation and the Standard Library

Swift basic types

Working with ranges

Range as Sequence

Throwing and catching errors

Container types

Arrays

Mutability and operations

Iterating, mapping, and reducing

Dictionaries

Initialization and mutability

Iterating, mapping, and reducing

Mastering concurrency with Dispatch

Tasks and queues

Synchronization with Dispatch

Thread safety through serial queues

Organizing execution with groups and semaphores

Example of a counting semaphore

Using groups

HTTP with URLSession

Making your first call with URLSession

Parsing responses with Decodable

Sending requests with Encodable

Summary

Working with Objective-C in a Mixed Code Base

Setting up your project

Importing Objective-C in Swift

Exposing Swift to Objective-C

Nullability and optionals in Objective-C

Using NS_ASSUME_NON_NULL_BEGIN and NS_ASSSUME_NON_NULL_END

Using nullable, nonnull, _Nullable, and _Nonnull

Naming, renaming, and refining Objective-C for Swift

Setting Objective-C names from Swift

Setting Swift names from Objective-C

Renaming classes

Renaming methods and enum cases

Lightweight generics in Objective-C

Using typed NSArray* in Objective-C

Generic classes in Objective-C

Cocoa design patterns in Swift

Delegation

Using delegation

Implementing delegation

Lazy initialization

Summary

Creational Patterns

The singleton pattern

Using singletons

Singletons in a nutshell

The factory method pattern

Using the factory method pattern

Advanced usage of the factory method pattern

Wrapping up

The abstract factory pattern

Using the abstract factory pattern

Going further with factory methods

Default implementations

Inheritance

Protocol extensions

Checklist for using the factory method pattern

The builder pattern

Model building

Going further: metaprogramming with Sourcery

The builder pattern in a nutshell

The prototype pattern

Leveraging the prototype pattern

Going further – NSCopying with Sourcery

Implementing NSCopying automatically

Implementing mutable objects

Implementing NSMutableCopying automatically

The prototype pattern in a nutshell

Summary

Structural Patterns

The adapter pattern

Using the adapter pattern

The basics

The classes to adapt

Using classes as adapters

Leveraging extensions

The adapter pattern in a nutshell

The decorator pattern

Using a decorator

Going further with decorator

Decoration in a nutshell

The facade pattern and proxy pattern

The facade pattern

Building a network cache with the facade pattern

Using the proxy pattern to implement request/response logging

The composite pattern

Using the composite pattern to represent tests and suites

The bridge pattern

Anatomy of the bridge pattern

Using the bridge pattern

The flyweight pattern

A shopping list using the flyweight pattern

Summary

Behavioral Patterns

The state pattern

The card reader

Using enums

Refactoring for maintainability

Extracting a single protocol

Implementing all states through structs, and moving the logic

Refactoring the context object

Using state machines

The observer pattern

Event-based programming

Using NotificationCenter

Using Key-Value Observing

Using KVO with existing Objective-C APIs

Using KVO with Swift

Observation using pure Swift

Using observation

The memento pattern

Components of the memento pattern

Implementing the memento pattern

Using the memento pattern

The visitor pattern

Visitable and visitor protocols

Contributors, thank you notes, and the visitor pattern

Using visitors

The strategy pattern

Components of the strategy pattern

The ice-cream shop example

Using the strategy pattern

Summary

Swift-Oriented Patterns

Getting started with protocol-oriented programming

A refresher on protocols

Adding requirements to protocols

Mutation and value types

Protocols are full-fledged types

Generics, conditional conformance, and associated types

Generics-based programming

Generic functions

Generic everything

Conditional conformance

Associated types

A word on Self requirement

Protocol-oriented programming

The type erasure pattern

Elements of type erasure

Closure-based type erasure

Boxing-based type erasure

The abstract base class

The private box

The public wrapper

The type erasure pattern – a summary

Template pattern with protocol-oriented programming

A recommendation engine

Summing up with the template method pattern

Summary

Using the Model-View-Controller Pattern

A refresher on MVC

The theory behind the MVC pattern

A pure MVC example

The model layer

The view layer

The controller layer

UIViewController

View controller life cycles

UIViewController anti-patterns

Early view instantiation

Early view access in initializer

Early view access in properties

Composition and child view controllers

Adding child view controllers

Removing child view controllers

Using view controller composition

The model layer

Using model controllers

Refactoring controllers

View controllers

Model controllers

The Controller

Summary

Model-View-ViewModel in Swift

Basics of the MVVM pattern

Refactoring MVC into MVVM

Model

ViewModel

View

Benefits and drawbacks of MVVM

Enhanced testing

Improved reusability

Drawbacks

MVVM and data binding

Implementing the Observable class

Implementing the Binding protocol

Two-way binding on UITextField

Using Observables with ViewModels

Summary

Implementing Dependency Injection

Dependency Injection, a primer

What is Dependency Injection?

Definition

Why DI is useful

Separation of concerns

Testability

Dependency Injection by example

Four ways to use Dependency Injection (with examples)

Constructor Injection

Property Injection

Method Injection

Ambient Context

Bind the dependencies

Composition Root

DI anti-patterns

Control Freak

Stable and volatile dependencies

Bastard Injection

Service Locator

Using a Dependency Injection Container

Why you should use a DI Container

The Typhoon framework

Swinject

Automatic Storyboard Injection

Summary

Futures, Promises, and Reactive Programming

Callbacks and closures

Closures and memory management

The issue with callbacks

Futures and promises

Futures and promises under the hood

Futures and promises frameworks for Swift

PromiseKit

Google Promises

Reactive programming

RxSwift

Observables and observers

Transformations

Schedulers

Asynchronous networking – an example

Summary

Modularize Your Apps with Swift Package Manager

Creating a library package

Adding features to the library

Adding more targets

Adding third-party dependencies

Using SPM with Xcode

Extracting and sharing a framework

Refactoring your code

Extracting a framework

Summary

Testing Your Code with Unit and UI Tests

Unit testing using XCTest

Testing an RPN Calculator app

TDD

What is an reverse polish notation calculator?

A simple RPN Calculator app

The first test

More tests

Refactoring the tests

Adding operations

Learnings from our first TDD code

Assertions

Advanced testing with mocks, spy, and others

Testing in Isolation

Dummy test double: when we don't need to test the collaborator

Fake test double: a simplified collaborator

Stub test double: a predefined collaborator

Spy test double: verifying collaboration

Mock test double: asserting collaboration

UI testing with Xcode

The importance of UI testing

Recording a UI test

Writing UI tests in code

Tips and tricks

Testing singletons

Testing Async code

Run only the test with the cursor

Summary

Going Out in the Open (Source)

Documenting Swift

The Markdown language

The anatomy of a documentation block

Rich content

Additional callouts

Structural annotations

Generating HTML docs

Publishing to GitHub Pages

Continuous integration

Travis CI

Configuring simple projects

Configuring more complex build scenarios

Configuring pure Swift projects

GitLab.com

Building and testing

Adding a linter, SwiftLint

Some final words on Travis and GitLab

Using fastlane for automated delivery

Getting started with fastlane

Your first lane

Fastlane beta

Using Travis to upload on tags

Becoming a maintainer, tips and tricks

The README.md file

The LICENSE.md file

The CODE_OF_CONDUCT.md file

Issues, Pull Requests, and more

No is temporary, yes is forever

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

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

发表评论

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

买过这本书的人还买过

读了这本书的人还在读

回顶部