实例介绍
【实例简介】iOS 14 Programming Fundamentals with Swift 7th Edition-2020-英文版
【实例截图】
【核心代码】
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Part I. Language
1. The Architecture of Swift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Ground of Being 3
Everything Is an Object? 5
Three Flavors of Object Type 6
Variables 6
Functions 8
The Structure of a Swift File 9
Scope and Lifetime 12
Object Members 13
Namespaces 13
Modules 14
Instances 15
Why Instances? 17
The Keyword self 19
Privacy 20
Design 22
2. Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Function Parameters and Return Value 25
Void Return Type and Parameters 29
Function Signature 30
External Parameter Names 30
Overloading 32
iiiDefault Parameter Values 33
Variadic Parameters 34
Ignored Parameters 34
Modifiable Parameters 35
Calling Objective-C with Modifiable Parameters 37
Called by Objective-C with Modifiable Parameters 38
Reference Type Modifiable Parameters 38
Function in Function 39
Recursion 40
Function as Value 40
Anonymous Functions 44
Using Anonymous Functions Inline 45
Anonymous Function Abbreviated Syntax 46
Define-and-Call 50
Closures 51
How Closures Improve Code 52
Function Returning Function 54
Closure Setting a Captured Variable 57
Closure Preserving Captured Environment 57
Escaping Closures 59
Curried Functions 60
Function References and Selectors 61
Function Reference Scope 63
Selectors 65
3. Variables and Simple Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Variable Scope and Lifetime 67
Variable Declaration 69
Computed Variable Initialization 73
Computed Variables 74
Computed Properties 75
Property Wrappers 77
Setter Observers 78
Lazy Initialization 79
Singleton 80
Lazy Initialization of Instance Properties 80
Built-In Simple Types 82
Bool 82
Numbers 84
String 92
iv | Table of ContentsCharacter and String Index 97
Range 102
Tuple 104
Optional 106
4. Object Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Object Type Declarations and Features 121
Initializers 123
Properties 130
Methods 133
Subscripts 134
Nested Object Types 137
Enums 138
Raw Values 139
Associated Values 141
Enum Case Iteration 143
Enum Initializers 144
Enum Properties 145
Enum Methods 146
Why Enums? 148
Structs 149
Struct Initializers 149
Struct Properties 151
Struct Methods 151
Struct as Namespace 152
Classes 152
Value Types and Reference Types 153
Subclass and Superclass 158
Class Initializers 164
Class Deinitializer 172
Class Properties 172
Static/Class Members 173
Polymorphism 174
Casting 178
Casting Down 179
Type Testing and Casting Down Safely 179
Type Testing and Casting Optionals 181
Bridging to Objective-C 182
Type References 183
From Instance to Type 183
Table of Contents | vFrom self to Type 183
Type as Value 187
Summary of Type Terminology 188
Comparing Types 188
Protocols 189
Why Protocols? 191
Adopting a Library Protocol 192
Protocol Type Testing and Casting 193
Declaring a Protocol 194
Protocol Composition 194
Class Protocols 195
Optional Protocol Members 197
Implicitly Required Initializers 199
Expressible by Literal 200
Generics 201
Generic Declarations 204
Contradictory Resolution Is Impossible 206
Type Constraints 207
Explicit Specialization 209
Generic Invariance 211
Associated Type Chains 212
Where Clauses 214
Extensions 217
Extending Protocols 219
Extending Generics 221
Umbrella Types 223
Any 223
AnyObject 225
AnyClass 227
Collection Types 228
Array 228
Dictionary 244
Set 252
5. Flow Control and More. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Flow Control 259
Branching 260
Loops 272
Jumping 278
Privacy 294
vi | Table of ContentsPrivate and Fileprivate 295
Public and Open 297
Privacy Rules 298
Introspection 298
Operators 299
Memory Management 303
Memory Management of Reference Types 303
Exclusive Access to Value Types 311
Miscellaneous Swift Language Features 313
Synthesized Protocol Implementations 313
Key Paths 316
Instance as Function 319
Dynamic Membership 320
Property Wrappers 322
Custom String Interpolation 325
Reverse Generics 327
Function Builders 329
Result 329
Part II. IDE
6. Anatomy of an Xcode Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
New Project 335
The Project Window 337
The Navigator Pane 339
The Inspectors Pane 344
The Editor 345
Project File and Dependents 348
Contents of the Project Folder 349
Groups 350
The Target 351
Build Phases 351
Build Settings 353
Configurations 354
Schemes and Destinations 355
From Project to Built App 358
Build Settings 360
Property List Settings 361
Nib Files 362
Table of Contents | viiResources 362
Code Files 364
Frameworks, SDKs, and Packages 364
The App Launch Process 369
The Entry Point 369
How an App Gets Going 370
App Without a Storyboard 372
Renaming Parts of a Project 373
7. Nib Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
The Nib Editor Interface 377
Document Outline 378
Canvas 380
Inspectors 382
Loading a Nib 383
Loading a View Controller Nib 383
Loading a Main View Nib 384
Loading a View Nib Manually 385
Connections 387
Outlets 387
The Nib Owner 389
Automatically Configured Nibs 392
Misconfigured Outlets 393
Deleting an Outlet 395
More Ways to Create Outlets 396
Outlet Collections 399
Action Connections 399
More Ways to Create Actions 401
Misconfigured Actions 403
Connections Between Nibs — Not! 404
Additional Configuration of Nib-Based Instances 404
8. Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
The Documentation Window 409
Class Documentation Pages 411
Quick Help 414
Symbol Declarations 416
Header Files 417
Sample Code 418
Internet Resources 419
viii | Table of Contents9. Life Cycle of a Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Environmental Dependencies 421
Conditional Compilation 422
Build Action 423
Permissible Runtime Environment 424
Backward Compatibility 425
Device Type 426
Arguments and Environment Variables 428
Version Control 429
Editing and Navigating Your Code 432
Text Editing Preferences 433
Multiple Selection 434
Autocompletion and Placeholders 435
Snippets 436
Refactoring and Structure Editing 437
Fix-it and Live Syntax Checking 439
Navigation 439
Finding 441
Running in the Simulator 443
Debugging 445
Caveman Debugging 445
The Xcode Debugger 449
Testing 456
Unit Tests 458
Interface Tests 463
Test Plans 465
Massaging the Report 467
Clean 468
Running on a Device 469
Obtaining a Developer Program Membership 469
Signing an App 470
Automatic Signing 471
Manual Signing 474
Running the App 475
Managing Development Certificates and Devices 476
Profiling 477
Gauges 477
Memory Debugging 478
Instruments 479
Localization 482
Table of Contents | ixCreating Localized Content 483
Testing Localization 487
Distribution 488
Making an Archive 488
The Distribution Certificate 489
The Distribution Profile 490
Distribution for Testing 491
Final App Preparations 493
Screenshots and Video Previews 495
Property List Settings 497
Submission to the App Store 498
Part III. Cocoa
10. Cocoa Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Subclassing 503
Categories and Extensions 506
How Swift Uses Extensions 506
How You Use Extensions 506
How Cocoa Uses Categories 507
Protocols 508
Optional Members 509
Informal Protocols 512
Some Foundation Classes 512
NSRange 513
NSNotFound 515
NSString and Friends 515
NSDate and Friends 518
NSNumber 520
NSValue 522
NSData 523
NSMeasurement and Friends 524
Equality, Hashability, and Comparison 524
NSArray and NSMutableArray 527
NSDictionary and NSMutableDictionary 529
NSSet and Friends 529
NSIndexSet 530
NSNull 531
Immutable and Mutable 532
x | Table of ContentsProperty Lists 533
Codable 534
Accessors, Properties, and Key–Value Coding 537
Swift Accessors 539
Key–Value Coding 540
How Outlets Work 541
Cocoa Key Paths 541
Uses of Key–Value Coding 542
KeyPath Notation 543
The Secret Life of NSObject 545
11. Cocoa Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
Reasons for Events 547
Subclassing 548
Notifications 549
Receiving a Notification 551
Unregistering 553
Posting a Notification 554
Timer 555
Delegation 556
Cocoa Delegation 557
Implementing Delegation 558
Data Sources 560
Actions 561
The Responder Chain 564
Nil-Targeted Actions 565
Key–Value Observing 566
Registration and Notification 567
Unregistering 568
Key–Value Observing Example 569
Swamped by Events 571
Delayed Performance 574
12. Memory Management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
Principles of Cocoa Memory Management 577
Rules of Cocoa Memory Management 578
What ARC Is and What It Does 579
How Cocoa Objects Manage Memory 580
Autorelease Pool 581
Memory Management of Instance Properties 583
Table of Contents | xiRetain Cycles and Weak References 584
Unusual Memory Management Situations 586
Notification Observers 587
KVO Observers 588
Timers 588
Other Unusual Situations 590
Nib Loading and Memory Management 590
Memory Management of CFTypeRefs 591
Property Memory Management Policies 593
Debugging Memory Management Mistakes 595
13. Communication Between Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
Visibility Through an Instance Property 597
Visibility by Instantiation 598
Getting a Reference 600
Visibility by Relationship 601
Global Visibility 601
Notifications and Key–Value Observing 603
The Combine Framework 604
Alternative Architectures 611
Model–View–Controller 611
Router and Data Space 611
Model–View–Presenter 612
Protocols and Reactive Programming 613
VIPER 614
SwiftUI 614
Function Builders and Modifiers 615
State Properties 616
Bindings 618
Passing Data Downhill 619
Passing Data Uphill 620
Custom State Objects 621
A. C, Objective-C, and Swift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663
好例子网口号:伸出你的我的手 — 分享!
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
网友评论
我要评论