Swift: The Complete Guide to Programming with Syntax, Debugging, and Concurrency

Оглавление⌄
Notes on Usage....5 Dedication....28 1 Introduction....29 1.1 About this Book....30 1.2 Welcome to Swift!....34 1.3 Why Learn Swift?....37 1.4 Swift Versus Other Programming Languages....41 1.4.1 Python....41 1.4.2 Java....44 1.4.3 C....46 1.4.4 JavaScript....46 1.4.5 Dart....48 1.4.6 Kotlin....49 1.4.7 C....50 1.4.8 Rust....52 1.4.9 Picking the Ideal Language....54 1.5 Setting Up the Development Environment....58 1.5.1 Preparing Your Mac....58 1.5.2 Alternative Options for Swift Development....67 1.6 Summary....70 2 Variables....71 2.1 Variables....71 2.1.1 About Variables and Constants....73 2.1.2 Declaring Simple Variables and Constants....74 2.1.3 Type Annotations....77 2.1.4 Comments....81 2.2 Boolean....85 2.2.1 About Booleans....85 2.2.2 AND Operator....86 2.2.3 OR Operator....89 2.2.4 Nested Conditions....91 2.3 Numbers....94 2.3.1 Numeric Types....94 2.3.2 Arithmetic Operators....106 2.3.3 Comparison Operators....113 2.3.4 Numeric Literals....115 2.4 Text....121 2.4.1 About Strings....121 2.4.2 Basic String Literals....126 2.4.3 Multiline String Literals....126 2.4.4 Escape Sequences....127 2.4.5 Concatenation....130 2.4.6 String Interpolation....132 2.4.7 Checking String Contents....133 2.4.8 Substrings....138 2.4.9 Modifying Strings....142 2.4.10 Comparison Operators....145 2.4.11 StringNumber Conversion....148 2.4.12 Regular Expressions....155 2.5 Dates and Times....161 2.5.1 Basic Data Types....161 2.5.2 Arithmetic Operations....164 2.5.3 Comparison....168 2.5.4 Measuring Durations....171 2.5.5 StringDate Conversion....173 2.5.6 Internationalization....180 2.6 Quantities....184 2.6.1 Units....184 2.6.2 Measurement....186 2.6.3 Unit Conversions....188 2.6.4 Arithmetic Operations....190 2.7 Tuples....195 2.7.1 Basic Tuples....195 2.7.2 Named Tuples....198 2.7.3 Tuple Type Annotations....199 2.7.4 Comparison....200 2.8 Type Aliases....202 2.8.1 Basic Types....202 2.8.2 Complex Types....204 2.9 Summary....205 3 Collections....206 3.1 Arrays....208 3.1.1 Creating Arrays....208 3.1.2 Arrays as Constants....210 3.1.3 Accessing Arrays....212 3.1.4 Array Derivation....218 3.1.5 Modifying Arrays....225 3.1.6 Iterating Through Arrays....230 3.2 Sets....242 3.2.1 Creating Sets....244 3.2.2 Sets as Constants....246 3.2.3 Accessing Sets....246 3.2.4 Set Derivation....248 3.2.5 Checking for Supersets....257 3.2.6 Modifying Sets....258 3.2.7 Iterating Through Sets....261 3.3 Dictionaries....265 3.3.1 Creating Dictionaries....266 3.3.2 Dictionaries as Constants....273 3.3.3 Accessing Dictionaries....274 3.3.4 Modifying Dictionaries....277 3.3.5 Iterating Through a Dictionary....280 3.4 Summary....283 4 Control Flow....285 4.1 Conditional Statements....287 4.1.1 If-Else....288 4.1.2 Logical Operators....299 4.1.3 Ternary Operator....305 4.1.4 Nil-Coalescing Operator....309 4.1.5 Switch....313 4.2 Loops....324 4.2.1 For-In Loops....324 4.2.2 While Loops....337 4.2.3 Repeat-While Loops....341 4.3 Control Transfer Statements....346 4.3.1 Break....346 4.3.2 Continue....349 4.3.3 Fallthrough....352 4.3.4 Guard....357 4.4 Summary....362 5 Functions....363 5.1 What Is a Function?....363 5.2 Defining and Calling Functions....369 5.2.1 Defining a Function....369 5.2.2 Calling a Function from the Program....370 5.2.3 Calling a Function from Another Function....373 5.2.4 Variable Scope in Functions....376 5.3 Input Parameters....381 5.3.1 Named Parameters....381 5.3.2 Omitting Argument Labels....387 5.3.3 Default Arguments....390 5.3.4 Guarding Functions....393 5.4 Returning Values....396 5.4.1 Returning Single Values....396 5.4.2 Returning Multiple Values....401 5.5 Variadic Parameters....409 5.6 Function Overloading....414 5.7 Inout Parameters....419 5.8 Nested Functions....423 5.9 Function Types....429 5.9.1 Basic....429 5.9.2 Function Types as Parameter Types....434 5.9.3 Function Types as Return Types....438 5.10 Closures....441 5.10.1 Closure Expressions....442 5.10.2 Trailing Closures....448 5.10.3 Escaping Closures....451 5.10.4 Autoclosures....458 5.11 Generic Functions....461 5.11.1 Generic Functions....461 5.11.2 Type Constraints....465 5.11.3 Generic Where Clauses....473 5.12 Summary....476 6 Optionals....477 6.1 What Are Optionals?....477 6.1.1 Tuple Optionals....478 6.1.2 Simple Variable Optionals....481 6.1.3 Collection Optionals....483 6.1.4 Function Optionals....484 6.2 Optional Binding....487 6.3 Implicitly Unwrapped Optionals....492 6.4 Optional Chaining....494 6.5 Summary....497 7 Enumerations....498 7.1 What Are Enumerations?....498 7.2 Declaring Enumerations....502 7.2.1 Case Values....502 7.2.2 Raw Values....505 7.2.3 Associated Values....509 7.3 Computed Properties....515 7.4 Functions in Enumerations....521 7.5 Iterating over Enumerations....525 7.5.1 Iterating over Case Values....525 7.5.2 Iterating over Raw Values....526 7.5.3 Iterating over Associated Values....527 7.6 Recursive Enumerations....531 7.7 Generic Enumerations....536 7.8 Summary....539 8 Structs....540 8.1 What Is a Struct?....541 8.2 Declaring Structs....545 8.2.1 Basic Struct Declaration....545 8.2.2 Mutable Properties....547 8.2.3 Complex Properties....548 8.2.4 Nested Structs....549 8.2.5 Default Property Values....553 8.2.6 Optional Properties....554 8.3 Static Properties....557 8.4 Computed Properties....561 8.4.1 Getters....561 8.4.2 Setters....564 8.5 Functions....568 8.5.1 Initialization....568 8.5.2 Nonmutating Functions....570 8.5.3 Mutating Functions....573 8.5.4 Static Functions....574 8.6 Encapsulation....577 8.6.1 Private Properties....578 8.6.2 Private Functions....582 8.7 Structs as Function Parameters....585 8.8 Generic Structs....588 8.9 Advanced Features....592 8.9.1 Lazy Properties....592 8.9.2 Property Observers....596 8.9.3 Property Wrappers....598 8.9.4 Subscripts....601 8.9.5 Failable Initialization....604 8.10 Summary....608 9 Classes....609 9.1 Declaring Classes....611 9.1.1 Basic Class Declaration....612 9.1.2 Reference Semantics....613 9.1.3 Composition....618 9.2 Functions....625 9.2.1 Mutability....625 9.2.2 Deinitialization....626 9.2.3 Convenience Initialization....631 9.3 Inheritance....633 9.3.1 Superclasses and Subclasses....633 9.3.2 Overriding Functions....644 9.3.3 Overriding Initializers....648 9.3.4 Overriding Computed Properties....651 9.3.5 Overriding Subscripts....655 9.3.6 Casting....658 9.3.7 AnyObject Type....666 9.4 Classes as Function Parameters....671 9.5 Memory Management....675 9.5.1 Strong References....675 9.5.2 Weak References....680 9.5.3 Unowned References....684 9.6 Summary....687 10 Protocols....688 10.1 Purpose of Protocols....688 10.2 Function Requirements....695 10.2.1 Nonmutating Function....695 10.2.2 Mutating Function....699 10.2.3 Static Function....702 10.3 Initializer Requirements....705 10.4 Property Requirements....709 10.4.1 Get Requirement....709 10.4.2 Get Set Requirement....711 10.4.3 Static Requirement....713 10.5 Implementing Multiple Protocols....716 10.6 Checking for Protocol Conformance....721 10.7 Protocols as Function Parameters....724 10.7.1 Protocol Type....724 10.7.2 Existential Type....725 10.7.3 Opaque Type....727 10.8 Associated Types....730 10.9 Using Standard Protocols....734 10.9.1 Equatable....734 10.9.2 Comparable....738 10.9.3 Identifiable....743 10.9.4 Hashable....745 10.9.5 CustomStringConvertible....748 10.10 Summary....751 11 Extensions....752 11.1 Extending Enumerations....754 11.2 Extending Structs....758 11.3 Extending Classes....762 11.4 Extending Protocols....765 11.5 Operator Extensions....770 11.5.1 Arithmetic and Boolean Operators....770 11.5.2 Equality and Comparison Operators....773 11.5.3 Prefix and Postfix Operators....776 11.5.4 Custom Operators....778 11.6 Extending Swift Data Types....782 11.6.1 Sample Usage....782 11.6.2 Avoiding Name Conflicts....783 11.7 Generic Extensions....786 11.8 Summary....789 12 Error Handling....790 12.1 Understanding Errors in Swift....792 12.2 Throwing Errors....797 12.2.1 Throwing Built-in Errors....797 12.2.2 Throwing Custom Errors....799 12.2.3 Propagating Errors....803 12.3 Catching Errors....806 12.3.1 Direct Pattern Matching....806 12.3.2 Error Pattern Matching....811 12.3.3 Localized Error Messages....816 12.3.4 Optional Try....820 12.4 Cleanup with Defer....825 12.5 Runtime Checks....831 12.5.1 Debug Runtime Checks....832 12.5.2 Release Runtime Checks....837 12.6 Summary....841 13 File Handling....842 13.1 Text Files....843 13.1.1 Reading Text Files....844 13.1.2 Writing Text Files....849 13.2 Binary Files....855 13.2.1 Reading Binary Files....856 13.2.2 Writing Binary Files....861 13.3 Working with Common Formats....867 13.3.1 JSON....868 13.3.2 Property List....877 13.4 File System Operations....889 13.4.1 Examining Folders....889 13.4.2 Manipulating Folders....893 13.4.3 Examining Files....900 13.4.4 Manipulating Files....902 13.5 Summary....910 14 Concurrency....911 14.1 What Is Concurrency?....911 14.2 Async Functions....915 14.2.1 Writing Async Functions....915 14.2.2 Calling Async Functions....918 14.2.3 Running Functions in Parallel....928 14.3 Tasks....934 14.3.1 Creating Tasks....935 14.3.2 Task Groups....942 14.3.3 Task Priorities....952 14.3.4 Task Cancellation....960 14.4 Async Streams....965 14.4.1 Starting an Async Stream....966 14.4.2 Canceling an Async Stream....969 14.4.3 Handling Async Stream Errors....971 14.5 Shared State Safety....974 14.5.1 Task-Local Values....975 14.5.2 Detached Tasks....981 14.5.3 Actors....983 14.5.4 Sendable Types....988 14.6 Summary....995 15 Modules in Swift....997 15.1 Introduction to Modules....998 15.1.1 What Is a Module?....998 15.1.2 Why Use Modules?....1002 15.2 Working with Frameworks....1010 15.2.1 Setting Up a New Framework....1010 15.2.2 Adding Code to a Framework....1013 15.2.3 Building a Framework....1014 15.2.4 Importing a Framework....1016 15.3 Working with Packages....1022 15.3.1 Setting Up a New Package....1023 15.3.2 Adding Code to a Package....1025 15.3.3 Importing a Package....1026 15.4 Access Control....1032 15.4.1 Open....1032 15.4.2 Public....1033 15.4.3 Internal....1034 15.4.4 File Private....1035 15.4.5 Private....1035 15.5 Summary....1037 16 Conclusion....1038 A Unit Testing....1042 A.1 Introduction to Unit Testing....1042 A.1.1 What Is a Unit Test?....1043 A.1.2 Test-Driven Development....1045 A.1.3 Unit Testing in Swift....1047 A.2 Unit Testing with XCTest....1049 A.2.1 Preparing a Testable Project....1049 A.2.2 Coding Unit Tests....1052 A.2.3 Executing Unit Tests....1056 A.2.4 Assertions....1058 A.2.5 Test Coverage....1059 A.3 Unit Testing with Swift Testing....1062 A.3.1 Preparing a Testable Project....1062 A.3.2 Coding Unit Tests....1065 A.3.3 Executing Unit Tests....1068 A.3.4 Test Macros....1070 A.3.5 Test Coverage....1070 A.4 Summary....1072 B Debugging....1073 B.1 Debugging in Xcode....1074 B.1.1 Creating a Sample Project....1074 B.1.2 Setting Breakpoints....1075 B.1.3 Starting a Debug Session....1077 B.1.4 Running Through a Debug....1078 B.1.5 Changing Breakpoints During Debug....1082 B.2 Advanced Debugging Tools....1084 B.2.1 Conditional Breakpoints....1084 B.2.2 Symbolic Breakpoints....1087 B.2.3 Performance Debugging....1090 B.3 Support Commands....1094 B.4 Summary....1096 C The Author....1097 Index....1099 Service Pages....1132 Legal Notes....1136
Описание
Коротко и по делу о том, что важно знать про swift.
Get to know Swift’s syntax and learn to work with elements such as variables and collections. This is your ultimate resource for Swift, the programming language for Apple devices! Use Swift’s built-in features for debugging, error handling, and memory management to streamline your development process. Follow along with downloadable code examples to get practical experience working with the language. Then move to more advanced topics like concurrency and custom modules. Become a Swift master in no time!
Learn to use variables, data types, and operators, and then string them together into collections. Your comprehensive guide to the Swift programming languageWork with variables, collections, enums, structs, and other language elementsPractice as you learn with downloadable code snippetsSwift SyntaxUnderstand the elements of the Swift programming language. Implement control flow statements to execute your code based on predefined conditions.
Features and Programming TechniquesWork with object-oriented programming techniques in Swift using enums and structs. Improve your code using Swift’s variety of features, including Automatic Reference Counting for memory management, built-in debugging, and nil value management with optionals.
Coding with SwiftStart developing with Swift right away! Download code samples and follow line-by-line instructions for everything from your first “Hello, world!” to custom reusable modules.
На этом основные моменты по теме закрыты.
Поделиться
Частые вопросы
Можно ли скачать «Swift: The Complete Guide to Programming with Syntax, Debugging, and Concurrency» бесплатно?
Да, «Swift: The Complete Guide to Programming with Syntax, Debugging, and Concurrency» доступна для бесплатного скачивания на нашем сайте в формате PDF. Ссылка на файл находится на этой странице.
В каком формате и какого размера файл?
Книга предоставляется в формате PDF, размер файла 12,3 МБ.
Кто автор и когда вышла книга?
автор — Koseoglu Kerem, издательство Rheinwerk Computing, год выпуска 2026, 1525 страниц.
О чём книга «Swift: The Complete Guide to Programming with Syntax, Debugging, and Concurrency»?
This is your ultimate resource for Swift, the programming language for Apple devices!