在好例子网,分享、交流、成长!
您当前所在位置:首页Swift 开发实例Swift语言基础 → Swift Programming The Big Nerd Ranch Guide-2020-英文版

Swift Programming The Big Nerd Ranch Guide-2020-英文版

Swift语言基础

下载此实例
  • 开发语言:Swift
  • 实例大小:6.57M
  • 下载次数:6
  • 浏览次数:19
  • 发布时间:2022-09-16
  • 实例类别:Swift语言基础
  • 发 布 人:zyl0462
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: Programming swift GUIDE 2020 GUID

实例介绍

【实例简介】Swift Programming The Big Nerd Ranch Guide-2020-英文版

【实例截图】

【核心代码】

Table of Contents
Introduction .................................................................................................................... xv
Learning Swift ........................................................................................................ xv
Why Swift? ............................................................................................................ xv
What About Objective-C? ........................................................................................ xvi
Prerequisites .......................................................................................................... xvi
How This Book Is Organized ................................................................................... xvi
How to Use This Book ........................................................................................... xvii
Challenges and For the More Curious ...................................................................... xviii
Typographical Conventions ..................................................................................... xviii
Necessary Hardware and Software ........................................................................... xviii
Before You Begin ................................................................................................. xviii
I. Getting Started .............................................................................................................. 1
1. Getting Started ...................................................................................................... 3
Getting Started with Xcode ................................................................................. 4
Playing in a Playground ..................................................................................... 6
Running Your Code ........................................................................................... 7
Troubleshooting Playgrounds ............................................................................... 8
Varying Variables and Printing to the Console ........................................................ 8
Adding Comments ........................................................................................... 11
You Are on Your Way! ..................................................................................... 11
Bronze Challenge ............................................................................................ 12
2. Types, Constants, and Variables .............................................................................. 13
Types ............................................................................................................. 13
Constants vs Variables ...................................................................................... 15
String Interpolation .......................................................................................... 16
Bronze Challenge ............................................................................................ 17
II. The Basics ................................................................................................................. 19
3. Conditionals ........................................................................................................ 21
if/else ............................................................................................................ 21
Ternary Operator ............................................................................................. 24
Nested ifs ....................................................................................................... 25
else if ............................................................................................................ 26
Bronze Challenge ............................................................................................ 26
4. Numbers ............................................................................................................. 27
Integers .......................................................................................................... 27
Creating Integer Instances ................................................................................. 29
Operations on Integers ...................................................................................... 31
Integer division ....................................................................................... 32
Operator shorthand .................................................................................. 33
Overflow operators .................................................................................. 33
Converting Between Integer Types ...................................................................... 35
Floating-Point Numbers .................................................................................... 36
Ranges of Numbers ......................................................................................... 38
Bronze Challenge ............................................................................................ 39
For the More Curious: Numeric Literals .............................................................. 39
viiSwift Programming
5. Switch ................................................................................................................ 41
Switch Syntax ................................................................................................. 42
Ranges ................................................................................................... 44
Value binding .......................................................................................... 45
where clauses .......................................................................................... 47
Tuples and Pattern Matching ............................................................................. 48
switch vs if/else .............................................................................................. 50
Bronze Challenge ............................................................................................ 52
Silver Challenge .............................................................................................. 52
6. Loops ................................................................................................................. 53
for-in Loops ................................................................................................... 54
where .................................................................................................... 57
while Loops .................................................................................................... 59
repeat-while Loops .......................................................................................... 60
Control Transfer Statements in Loops ................................................................. 61
Silver Challenge .............................................................................................. 64
7. Strings ............................................................................................................... 65
Working with Strings ....................................................................................... 65
Characters .............................................................................................. 67
Unicode ......................................................................................................... 68
Unicode scalars ....................................................................................... 68
Canonical equivalence .............................................................................. 70
Bronze Challenge ............................................................................................ 74
Silver Challenge .............................................................................................. 74
For the More Curious: Substrings ....................................................................... 74
For the More Curious: Multiline Strings .............................................................. 77
III. Collections and Functions ............................................................................................ 79
8. Arrays ................................................................................................................ 81
Creating an Array ............................................................................................ 82
Accessing and Modifying Arrays ....................................................................... 84
Combining Arrays ........................................................................................... 87
Array Equality ................................................................................................ 88
Immutable Arrays ............................................................................................ 89
Documentation ................................................................................................ 89
Bronze Challenge ............................................................................................ 92
Silver Challenge .............................................................................................. 92
9. Optionals ............................................................................................................ 93
Optional Types ................................................................................................ 94
Optional Binding ............................................................................................. 96
Implicitly Unwrapped Optionals ......................................................................... 99
Optional Chaining .......................................................................................... 100
Modifying an Optional in Place ........................................................................ 101
The Nil Coalescing Operator ........................................................................... 102
Bronze Challenge ........................................................................................... 103
Silver Challenge ............................................................................................ 103
Gold Challenge .............................................................................................. 103
10. Dictionaries ..................................................................................................... 105
Creating a Dictionary ..................................................................................... 106
viiiSwift Programming
Accessing and Modifying Values ...................................................................... 107
Adding and Removing Values .......................................................................... 109
Looping over a Dictionary ............................................................................... 110
Immutable Dictionaries ................................................................................... 111
Translating a Dictionary to an Array ................................................................. 111
Silver Challenge ............................................................................................ 112
Gold Challenge .............................................................................................. 112
11. Sets ................................................................................................................ 113
What Is a Set? ............................................................................................... 113
Getting a Set ................................................................................................. 114
Working with Sets .......................................................................................... 115
Unions ................................................................................................. 116
Intersections .......................................................................................... 117
Disjoint ................................................................................................ 118
Moving Between Types ................................................................................... 119
Bronze Challenge ........................................................................................... 121
Silver Challenge ............................................................................................ 121
12. Functions ........................................................................................................ 123
A Basic Function ........................................................................................... 124
Function Parameters ....................................................................................... 125
Parameter names .................................................................................... 126
Default parameter values ......................................................................... 127
In-out parameters ................................................................................... 129
Returning from a Function .............................................................................. 130
Nested Function Definitions and Scope .............................................................. 131
Multiple Returns ............................................................................................ 132
Optional Return Types .................................................................................... 133
Exiting Early from a Function .......................................................................... 134
Function Types .............................................................................................. 135
Bronze Challenge ........................................................................................... 136
Silver Challenge ............................................................................................ 136
For the More Curious: Void ............................................................................. 137
For the More Curious: Variadic Parameters ......................................................... 138
13. Closures .......................................................................................................... 139
Closure Syntax .............................................................................................. 139
Closure Expression Syntax .............................................................................. 141
Functions as Arguments .................................................................................. 144
Closures Capture Their Enclosing Scope ............................................................ 146
Functional Programming ................................................................................. 150
Higher-Order Functions .................................................................................. 150
map(_:) ................................................................................................ 151
filter(_:) ................................................................................................ 152
reduce(_:_:) ........................................................................................... 153
Bronze Challenge ........................................................................................... 154
Silver Challenge ............................................................................................ 154
Gold Challenge .............................................................................................. 154
For the More Curious: Functions as Return Types ................................................ 155
IV. Enumerations, Structures, and Classes .......................................................................... 157
ixSwift Programming
14. Enumerations ................................................................................................... 159
Basic Enumerations ........................................................................................ 159
Enumerations with Raw Values ........................................................................ 163
Methods ....................................................................................................... 165
Associated Values .......................................................................................... 169
Bronze Challenge ........................................................................................... 172
Silver Challenge ............................................................................................ 172
For the More Curious: Recursive Enumerations ................................................... 172
15. Structs and Classes ........................................................................................... 175
A New Project .............................................................................................. 175
Structures ..................................................................................................... 181
Instance Methods ........................................................................................... 184
Mutating methods .................................................................................. 185
Classes ......................................................................................................... 186
A Monster class ..................................................................................... 186
Inheritance ............................................................................................ 187
Looking Ahead: What Is the Real Difference? .................................................... 194
Bronze Challenge ........................................................................................... 197
Silver Challenge ............................................................................................ 197
For the More Curious: Type Methods ................................................................ 197
16. Properties ........................................................................................................ 199
Basic Stored Properties ................................................................................... 200
Nested Types ................................................................................................. 201
Lazy Stored Properties .................................................................................... 201
Computed Properties ...................................................................................... 204
A getter and a setter ............................................................................... 205
Property Observers ......................................................................................... 206
Type Properties .............................................................................................. 208
Access Control .............................................................................................. 211
Controlling getter and setter visibility ........................................................ 213
Bronze Challenge ........................................................................................... 215
Silver Challenge ............................................................................................ 215
Gold Challenge .............................................................................................. 215
For the More Curious: Key Paths ...................................................................... 216
17. Initialization ..................................................................................................... 217
Initializer Syntax ............................................................................................ 217
Struct Initialization ......................................................................................... 218
Default initializers for structs ................................................................... 218
Custom initializers for structs ................................................................... 219
Class Initialization ......................................................................................... 223
Default initializers for classes .................................................................. 223
Initialization and class inheritance ............................................................. 224
Required initializers for classes ................................................................ 230
Deinitialization ...................................................................................... 231
Failable Initializers ......................................................................................... 232
A failable Town initializer ....................................................................... 233
Initialization Going Forward ............................................................................ 235
Silver Challenge ............................................................................................ 236
xSwift Programming
Gold Challenge .............................................................................................. 236
For the More Curious: Initializer Parameters ....................................................... 237
18. Value vs Reference Types .................................................................................. 239
Value Semantics ............................................................................................ 239
Reference Semantics ....................................................................................... 242
Constant Value and Reference Types ................................................................. 244
Using Value and Reference Types Together ........................................................ 246
Copying ....................................................................................................... 247
Equality vs Identity ........................................................................................ 249
What Should I Use? ....................................................................................... 251
For the More Curious: Copy on Write ............................................................... 252
V. Advanced Swift ......................................................................................................... 261
19. Protocols ......................................................................................................... 263
Formatting a Table of Data .............................................................................. 264
Protocols ...................................................................................................... 268
Protocol Conformance .................................................................................... 271
Protocol Inheritance ....................................................................................... 273
Protocols as Types ......................................................................................... 274
Protocol Composition ..................................................................................... 276
Mutating Methods .......................................................................................... 278
Bronze Challenge ........................................................................................... 280
Silver Challenge ............................................................................................ 280
Electrum Challenge ........................................................................................ 280
Gold Challenge .............................................................................................. 280
20. Extensions ....................................................................................................... 281
Extending an Existing Type ............................................................................. 282
Extending Your Own Type .............................................................................. 283
Using extensions to add protocol conformance ............................................ 284
Adding an initializer with an extension ...................................................... 285
Nested types and extensions .................................................................... 286
Extensions with methods ......................................................................... 287
Bronze Challenge ........................................................................................... 288
Silver Challenge ............................................................................................ 288
21. Generics .......................................................................................................... 289
Generic Data Structures .................................................................................. 290
Generic Functions and Methods ....................................................................... 292
Type Constraints ............................................................................................ 295
Associated Types ........................................................................................... 297
Type Constraints in where Clauses .................................................................... 300
Generic Composition and Opaque Types ............................................................ 303
Bronze Challenge ........................................................................................... 308
Silver Challenge ............................................................................................ 308
Gold Challenge .............................................................................................. 308
For the More Curious: Understanding Optionals .................................................. 309
22. Protocol Extensions ........................................................................................... 311
Modeling Exercise ......................................................................................... 312
Extending Exercise ......................................................................................... 313
Self Types and Type Values ............................................................................. 315
xiSwift Programming
Protocol Extension where Clauses ..................................................................... 316
Default Implementations with Protocol Extensions ............................................... 318
Implementation Conflicts ................................................................................ 320
Bronze Challenge ........................................................................................... 322
Silver Challenge ............................................................................................ 322
Gold Challenge .............................................................................................. 322
For the More Curious: Polymorphism and Protocol-Oriented Programming ............... 323
23. Error Handling ................................................................................................. 325
Classes of Errors ........................................................................................... 325
Lexing an Input String .................................................................................... 326
Catching Errors ............................................................................................. 336
Parsing the Token Array ................................................................................. 337
Handling Errors by Sticking Your Head in the Sand ............................................. 342
Swift Error-Handling Philosophy ...................................................................... 344
Bronze Challenge ........................................................................................... 346
Silver Challenge ............................................................................................ 346
Gold Challenge .............................................................................................. 346
For the More Curious: Storing Failable Results for Later ....................................... 347
24. Memory Management and ARC .......................................................................... 349
Memory Allocation ........................................................................................ 349
Strong Reference Cycles ................................................................................. 350
Breaking Strong Reference Cycles with weak ..................................................... 358
Reference Cycles with Closures ....................................................................... 359
Escaping and Non-Escaping Closures ................................................................ 364
Tin Challenge ................................................................................................ 366
Bronze Challenge ........................................................................................... 366
Gold Challenge .............................................................................................. 366
For the More Curious: A Bit of History ............................................................. 367
For the More Curious: Do I Have the Only Reference? ......................................... 368
25. Equatable, Comparable, and Hashable .................................................................. 369
Equatable ...................................................................................................... 369
Infix operators ....................................................................................... 372
Buy one method, get another free! ............................................................ 372
Comparable ................................................................................................... 373
Protocol inheritance ................................................................................ 375
Hashable ...................................................................................................... 376
Custom hashing ..................................................................................... 377
Bronze Challenge ........................................................................................... 379
Silver Challenge ............................................................................................ 379
Gold Challenge .............................................................................................. 380
Platinum Challenge ........................................................................................ 380
For the More Curious: Custom Operators ........................................................... 381
26. Property Wrappers ............................................................................................ 385
Defining a Property Wrapper ........................................................................... 386
Additional configuration .......................................................................... 389
Accessing the Wrapper Itself ........................................................................... 391
Projecting Related Values ................................................................................ 392
Bronze Challenge ........................................................................................... 394
xiiSwift Programming
Silver Challenge ............................................................................................ 394
Gold Challenge .............................................................................................. 394
VI. Writing Applications ................................................................................................. 395
27. Command-Line Utilities ..................................................................................... 397
Introduction to the Command Line ................................................................... 397
Building the Word Finder ................................................................................ 400
Loading the words from disk ................................................................... 405
Retrieving Command-Line Arguments ............................................................... 406
Receiving Input Interactively ........................................................................... 409
Running Your App from the Command Line ...................................................... 412
Parsing Command-Line Arguments with ArgumentParser ...................................... 413
Adding ArgumentParser to your project ..................................................... 413
Declaring arguments for ArgumentParser to parse ........................................ 417
Silver Challenge ............................................................................................ 421
Gold Challenge .............................................................................................. 421
28. iOS and macOS Apps ....................................................................................... 423
Getting Started with TahDoodle ........................................................................ 424
That is some View ......................................................................................... 427
Displaying Dynamic Data ................................................................................ 431
Accepting User Input ...................................................................................... 438
Sharing references to value-type data ........................................................ 441
Interlude: Troubleshooting with property observers ...................................... 446
Observing Changes to the Store ....................................................................... 447
Saving and Loading User Data ......................................................................... 449
Supporting macOS ......................................................................................... 454
Bronze Challenge ........................................................................................... 457
Silver Challenge ............................................................................................ 457
Gold Challenge .............................................................................................. 457
29. Conclusion .............................................................................................................. 459
Where to Go from Here? ........................................................................................ 459
Shameless Plugs .................................................................................................... 459
An Invitation to the Community ............................................................................... 460
Index ........................................................................................................................... 461


实例下载地址

Swift Programming The Big Nerd Ranch Guide-2020-英文版

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
;
报警