没有合适的资源?快使用搜索试试~ 我知道了~
首页objc.io - Advanced Swift_Swift 5.pdf
objc.io - Advanced Swift_Swift 5.pdf
需积分: 50 423 浏览量
更新于2023-03-03
评论 1
收藏 40.67MB PDF 举报
[MG] objc.io - Advanced Swift_Swift 5.pdf. 已经更新到 Swift5.
资源详情
资源评论
资源推荐


Version 4.0 (May 2019)
© 2019 Kugler und Eidhof GbR
All Rights Reserved
For more books, articles, and videos visit us at https://www.objc.io.
Email: mail@objc.io
Twitter: @objcio

1 Introduction 10
Who Is This Book For? 12
Themes 13
Terminology 16
Swift Style Guide 20
Revision History 22
2 Built-In Collections 24
Arrays 25
Arrays and Mutability 25
Array Indexing 27
Transforming Arrays 29
Array Slices 41
Dictionaries 43
Mutating Dictionaries 44
Some Useful Dictionary Methods 44
Hashable Requirement 46
Sets 47
Set Algebra 48
Index Sets and Character Sets 49
Using Sets Inside Closures 50
Ranges 51
Countable Ranges 52
Partial Ranges 53
Range Expressions 53
Recap 54
3 Optionals 56
Sentinel Values 57
Replacing Sentinel Values with Enums 59
A Tour of Optional Techniques 61
if let 61
while let 62
Doubly Nested Optionals 64
if var and while var 65
Scoping of Unwrapped Optionals 66
Optional Chaining 70

The nil-Coalescing Operator 73
Using Optionals with String Interpolation 75
Optional map 77
Optional atMap 79
Filtering Out nils with compactMap 80
Equating Optionals 81
Comparing Optionals 84
When to Force-Unwrap 84
Improving Force-Unwrap Error Messages 86
Asserting in Debug Builds 87
Implicitly Unwrapped Optionals 89
Implicit Optional Behavior 90
Recap 90
4 Functions 91
Overview 92
Flexibility through Functions 99
Functions as Data 103
Functions as Delegates 110
Delegates, Cocoa Style 110
Delegates That Work with Structs 111
Functions Instead of Delegates 113
inout Parameters and Mutating Methods 116
Nested Functions and inout 119
When & Doesn’t Mean inout 119
Properties 120
Change Observers 121
Lazy Stored Properties 123
Subscripts 125
Custom Subscripts 126
Advanced Subscripts 126
Key Paths 128
Key Paths Can Be Modeled with Functions 130
Writable Key Paths 131
The Key Path Hierarchy 134
Key Paths Compared to Objective-C 135
Future Directions 135
Autoclosures 135
The @escaping Annotation 138
withoutActuallyEscaping 140

Recap 141
5 Structs and Classes 142
Value Types and Reference Types 143
Mutation 147
Mutating Methods 151
inout Parameters 152
Lifecycle 153
Reference Cycles 153
Closures and Reference Cycles 158
Choosing between Unowned and Weak References 160
Deciding between Structs and Classes 161
Classes with Value Semantics 162
Structs with Reference Semantics 163
Copy-On-Write Optimization 165
Copy-On-Write Tradeoffs 166
Implementing Copy-On-Write 167
Recap 171
6 Enums 173
Overview 174
Enums Are Value Types 175
Sum Types and Product Types 177
Pattern Matching 179
Pattern Matching in Other Contexts 183
Designing with Enums 185
Switch Exhaustively 186
Make Illegal States Impossible 187
Use Enums for Modeling State 191
Choosing between Enums and Structs 195
Parallels between Enums and Protocols 197
Use Enums to Model Recursive Data Structures 200
Raw Values 206
The RawRepresentable Protocol 207
Manual RawRepresentable Conformance 208
RawRepresentable for Structs and Classes 209
Internal Representation of Raw Values 210
Enumerating Enum Cases 211
剩余430页未读,继续阅读


















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0