售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Swift High Performance
Table of Contents
Swift High Performance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Exploring Swift's Power and Performance
Swift speed
Welcome to Swift
Why should I learn Swift?
Swift's features and benefits
Clean and beautiful
No semicolons
Type inference
Other clean code Swift features
A clean code summary
Safe
Optionals
Error handling
Rich type system
Powerful value types
A multiparadigm language
Object oriented
Protocol oriented
Functional
Generic purpose
Fast
Swift interoperability
Using Objective-C in Swift
Setup
The application target
The framework target
Calling Objective-C code
Using Swift in Objective-C
Features of Swift that are not available in Objective-C
Performance – meaning and key metrics
Everyday code performance
The importance of performance
The key metrics
Summary
2. Making a Good Application Architecture in Swift
Making a Swift application
The differences between variables and constants
Immutability
Multithreading
Value types and immutability
Reference types
Value types
The power of structures
Representing the state with classes
Representing the absence of values with optionals
Optional and non-optional types
Safe nil handling
Using optionals
Wrapping up on optionals
Functional programming
Function types
Splitting the code
The closure expression
Type inference
Implicit return type
Shorthand argument names
Trailing closure syntax
The standard library
The map method
map for optionals
The reduce method
The filter method
Generics
Generic functions
Type constraints
The generic type and collections
Safety
Dangerous operations
Summary
3. Testing and Identifying Slow Code with the Swift Toolkit
REPL
Playgrounds
Interactive documentation
The folder structure
The source folder
Resources
Pages
XCPlayground
LLDB
REPL in Xcode
Console logs
Performance measuring in unit tests
Instruments
A reminder
Summary
4. Improving Code Performance
Understanding performance optimization
Explicit
Implicit
Optimization checklist
Swift code compilation
Constants and variables
Method calls
Functions and methods
Global functions
Type methods
Static methods
Instance methods
Comparing function speed
Functions and methods usage summary
Intelligent code
Dangerous functions
Console print
Removing print logs
Comment out
Using build configurations
Using nonoptimizable constants
Improving speed
Final
Inline functions
Value objects and reference objects
Memory allocation
Swift arrays and unsafe C arrays
Function parameters
Creating a pointer to an existing variable
Allocating memory for the pointer
Comparing Swift arrays with unsafe C arrays
A summary of working with pointers
Avoiding Objective-C
Avoiding exposing Swift to Objective-C
Dynamic
A summary of avoiding Objective-C
Summary
5. Choosing the Correct Data Structure
An overview of data structures
Collection types
Swift standard library collections
Arrays
Using arrays
Fast operations
Slower operations
Search
Sort
Sets
Using sets
Set operations
Dictionaries
Collection memory allocation
Empty
Reserve capacity
Default values
The CollectionType protocol methods
Protocol extensions
Accelerate and Surge
Other collections
Summary
6. Architecting Applications for High Performance
Achieving high performance
Device architecture
Concurrency overview
Threads
Thread complexity
Solution for threads
GCD
Queues
Main queues
Concurrent queues
Own queues
Tasks
Adding tasks to the queue
Synchronous dispatch
Asynchronous dispatch
Operation queues
Designing asynchronous code
Avoiding state
Capture list
Immutable state
Divide and conquer
Controlling the lifetime
Applying the @autoclosure and @noescape attributes
@autoclosure
@noescape
@autoclosure (escaping)
Summary
7. The Importance of Being Lazy
The lazy mindset
Separation
Do work on demand
Approximate results
Lazy loading
Global constants and variables
Type properties
Lazy properties
Computed properties
Lazy collections and evaluation
Sequences and collections
Sequences
Collections
Implementing our own sequence and collection
Using lazy
Using the lazy sequence
Using a lazy collection
Summary
8. Discovering All the Underlying Swift Power
How Swift is so fast
Swift command line tools
xcrun
The Swift compiler
swift
swiftc
The Swift compilation process and swiftc
Swift AST
SIL
LLVM IR
Other swiftc options
Analyzing executable files
Summary
Final thoughts
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜