在好例子网,分享、交流、成长!
您当前所在位置:首页Swift 开发实例Swift语言基础 → Mastering Swift

Mastering Swift

Swift语言基础

下载此实例
  • 开发语言:Swift
  • 实例大小:7.55M
  • 下载次数:8
  • 浏览次数:68
  • 发布时间:2022-02-24
  • 实例类别:Swift语言基础
  • 发 布 人:Dustin宇
  • 文件格式:.pdf
  • 所需积分:5
 相关标签: master swift ASTER if MA

实例介绍

【实例简介】Mastering Swift

【实例截图】

【核心代码】

Table of Contents
Preface 1
Chapter 1: Taking the First Steps with Swift 6
What is Swift? 6
Swift features 9
Playgrounds 10
Getting started with playgrounds 10
iOS, tvOS, and macOS playgrounds 14
Showing images in a playground 14
Creating and displaying graphs in playgrounds 18
What playgrounds are not 19
Swift language syntax 20
Comments 20
Semicolons 23
Parentheses 24
Curly brackets 25
An assignment operator does not return a value 26
Spaces are optional in conditional and assignment statements 27
Hello World 28
Summary 29
Chapter 2: Learning about Variables, Constants, Strings, and Operators 30
Constants and variables 31
Defining constants and variables 32
Type safety 33
Type inference 34
Explicit types 35
Numeric types 36
Integer types 36
Floating-point and Double values 39
The Boolean type 41
The String type 42
Tuples 47
Enumerations 48
Operators 52
Assignment operator 52
Comparison operators 53
Arithmetic operators 53
Remainder operator 54
Compound assignment operators 54
Table of Contents
[ ii ]
Closed range operator 55
Half open range operator 55
Ternary conditional operator 56
Logical NOT operator 56
Logical AND operator 56
Logical OR operator 57
Summary 57
Chapter 3: Optional Types 58
Introducing optionals 58
The need for optional types in Swift 60
Defining an optional 61
Using optionals 61
Forced unwrapping of an optional 61
Optional binding 62
Optional types with tuples 64
Optional chaining 64
The nil coalescing operator 64
Summary 65
Chapter 4: Using Swift Collections 66
Swift collection types 66
Mutability 67
Arrays 67
Creating and initializing arrays 68
Accessing the array element 69
Counting the elements of an array 70
Is the array empty? 71
Shuffling an array 72
Appending to an array 72
Inserting a value into an array 73
Replacing elements in an array 73
Removing elements from an array 73
Merging two arrays 74
Retrieving a subarray from an array 74
Making bulk changes to an array 75
Algorithms for arrays 76
Sort 76
Sorted 77
Filter 77
Map 78
Count 79
forEach 79
Iterating over an array 80
Dictionaries 81
Creating and initializing dictionaries 81
Table of Contents
[ iii ]
Accessing dictionary values 82
Counting the key or values in a dictionary 82
Is the dictionary empty? 83
Updating the value of a key 83
Adding a key-value pair 84
Removing a key-value pair 84
Set 85
Initializing a set 85
Inserting items into a set 86
Determining the number of items in a set 86
Checking whether a set contains an item 87
Iterating over a set 87
Removing items in a set 87
Set operations 88
Summary 90
Chapter 5: Control Flow 91
What have we learned so far? 91
Curly brackets 92
Parentheses 92
Control flow 93
Conditional statements 93
The if statement 93
Conditional code execution with the if...else statement 94
The guard statement 95
The for-in loop 97
Using the for-in loop 97
The while loop 98
Using the while loop 99
Using the repeat-while loop 99
The switch statement 100
Switch on tuples 105
Match on wildcard 106
Using case and where statements with conditional statements 107
Filtering with the where statement 107
Filtering with the for-case statement 108
Using the if-case statement 110
Control transfer statements 111
The continue statement 111
The break statement 112
The fallthrough statement 113
Summary 113
Chapter 6: Functions 114
Using a single parameter function 115
Using a multi-parameter function 116
Table of Contents
[ iv ]
Defining a parameter's default values 117
Returning multiple values from a function 118
Adding external parameter names 120
Using variadic parameters 122
Inout parameters 122
Omitting argument labels 123
Putting it all together 124
Summary 125
Chapter 7: Classes, Structures, and Protocols 126
What are classes and structures? 127
Similarities between classes and structures 127
Differences between classes and structures 127
Value versus reference types 128
Creating a class or structure 128
Properties 129
Stored properties 129
Computed properties 131
Property observers 134
Methods 135
Custom initializers 137
Internal and external parameter names 139
Failable initializers 140
Access controls 142
Inheritance 143
Overriding methods and properties 146
Overriding methods 147
Overriding properties 149
Preventing overrides 149
Protocols 150
Protocol syntax 150
Property requirements 151
Method requirements 152
Extensions 154
Optional chaining 155
Summary 157
Chapter 8: Using Protocols and Protocol Extensions 158
Protocols as types 159
Polymorphism with protocols 161
Type casting with protocols 161
Protocol extensions 163
Do I need to use protocols? 172
Swift's standard library 172
Table of Contents
[ v ]
Summary 174
Chapter 9: Protocol Oriented Design 175
Requirements 176
Object-oriented design 176
Protocol-oriented design 182
Protocol inheritance 183
Protocol composition 184
Protocol-oriented design 185
Using the where statement with protocols 188
Structures versus classes 189
The array structure 190
Summary 190
Chapter 10: Generics 192
Introducing generics 192
Generic functions 193
Generic types 197
Conditionally adding extensions with generics 201
Conditional conformance 202
Generic subscripts 203
Associated types 203
Summary 206
Chapter 11: Availability and Error Handling 207
Native error handling 207
Representing errors 208
Throwing errors 209
Catching errors 211
The availability attribute 215
Summary 217
Chapter 12: Custom Subscripting 218
Introducing subscripts 218
Subscripts with Swift arrays 219
Creating and using custom subscripts 220
Read-only custom subscripts 221
Calculated subscripts 221
Subscript values 222
External names for subscripts 222
Multidimensional subscripts 223
Dynamic member lookup 226
When not to use a custom subscript 228
Summary 229
Chapter 13: Working with Closures 230
Table of Contents
[ vi ]
An introduction to closures 230
Simple closures 231
Shorthand syntax for closures 234
Using closures with Swift's array algorithms 237
Changing functionality 241
Selecting a closure based on results 243
Summary 245
Chapter 14: Concurrency and Parallelism in Swift 247
Concurrency and parallelism 248
Grand Central Dispatch 249
Calculation type 251
Creating queues 251
Creating and using a concurrent queue 252
Creating and using a serial queue 254
Async versus sync 256
Executing code on the main queue function 256
Using asyncAfter 257
Using the Operation and OperationQueue types 258
Using BlockOperation 258
Using the addOperation() method of the operation queue 260
Subclassing the Operation class 262
Summary 264
Chapter 15: Custom Types 265
Value types and reference types 265
Recursive data types for reference types 270
Inheritance for reference types 272
Dynamic dispatch 275
Copy-on-write 276
Implementing the equatable protocol 282
Summary 284
Chapter 16: Memory Management 285
How ARC works 286
Strong reference cycles 288
Summary 292
Chapter 17: Swift Formatting and Style Guider 293
What is a programming style guide? 293
Your style guide 294
Do not use semicolons at the end of statements 295
Do not use parentheses for conditional statements 295
Naming 296
Custom types 296
Functions and methods 296
Table of Contents
[ vii ]
Constants and variables 296
Indenting 297
Comments 298
Using the self keyword 298
Constants and variables 299
Optional types 299
Using optional binding 299
Using optional chaining instead of optional binding for multiple unwrapping 301
Using type inference 301
Using shorthand declaration for collections 302
Using switch rather than multiple if statements 302
Don't leave commented-out code in your application 303
Summary 303
Chapter 18: Adopting Design Patterns in Swift 304
What are design patterns? 305
Creational patterns 306
The singleton design pattern 307
Understanding the problem 308
Understanding the solution 308
Implementing the singleton pattern 308
The builder design pattern 310
Understanding the problem 310
Understanding the solution 310
Implementing the builder pattern 311
Structural design patterns 316
The bridge pattern 317
Understanding the problem 317
Understanding the solution 317
Implementing the bridge pattern 317
The facade pattern 321
Understanding the problem 322
Understanding the solution 322
Implementing the facade pattern 322
The proxy design pattern 325
Understanding the problem 325
Understanding the solution 325
Implementing the proxy pattern 325
Behavioral design patterns 328
The command design pattern 328
Understanding the problem 328
Understanding the solution 329
Implementing the command pattern 329
The strategy pattern 331
Understanding the problem 331
Understanding the solution 331
Implementing the strategy pattern 331
Summary 333
Other Books You May Enjoy 335
Table of Contents
[ viii ]
Index 

标签: master swift ASTER if MA

实例下载地址

Mastering Swift

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

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

网友评论

发表评论

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

查看所有0条评论>>

小贴士

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

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

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警