A set of playgrounds that explains a Swift topic.
These playgrounds cover a technical topic of Swift with examples. All explanations are in French.
Here's the list:
-
@(non)escaping closures: What are the differences between
@nonescaping
and@escaping
? -
@autoclosure: How to transform a function argument into a closure?
-
@discardableResult: How to ignore the warning if the returned value of a function is not affected?
-
ARC & Memory Leaks: How the Automatic Reference Couting (ARC) works – What is a memory leak and how do you fix it?
-
ARC, Retain Cycle & Memory Leaks: How the Automatic Reference Couting (ARC) works – What is a memory leak and how do you fix it?
-
Access Control: How can we restrict certain parts of our code, or on the contrary make it open?
-
Array extensions & tricks: Functions of the standard library explained & some useful extensions.
-
Custom Prefix, Postfix, Infix Operators: How do you create your own prefix / postfix / infix operators that act as functions behind the scenes?
-
Defer: How to execute code just before the program leaves the scope of a function?
-
Dependency Injection: What is injection dependence? - Why use dependency injection? - What are the different types of dependency injections?
-
Enum extensions & tricks:
enum
with & without associated value,switch
,if case let
,guard case let
,for case ... in
,indirect enum
. -
ExpressibleByStringLiteral: What is the purpose of the
ExpressibleByStringLiteral
protocol? – How do you conform to it? -
Grand Central Dispatch: asynchronous & synchronous execution,
DispatchQueue
,QOS
,DispatchWorkItem
,DispatchGroup
,DispatchSemaphore
and more. -
High Order Functions:
filter
,map
,reduce
,compactMap
,flatMap
&contains
functions explained through examples. -
Keypath: What is a keypath? – Why you should use it? – How to create your own predicates?
-
Lazy Property: What is a
lazy
property? – For which use case is it used? – What are the differences between alazy
property and a computed property? -
Literal Expression & Log function:
#file
,#filePath
,#fileID
,#line
,#column
,#function
– How to create a function for logging? -
Opaque Return Type: What is a opaque return type? – What are the limitations of
some
? – How to compare two objects of an opaque return type? – What are the limits? -
Property Observers: What is a property observers? – How and when to use such a property?
-
Protocols: How to declare and conform to a protocol? – How to create default implementations with protocol extension? – What is protocol inheritance?
-
RawRepresentable: What is the purpose of the
RawRepresentable
protocol? – How do you conform to it? -
Static properties & functions: What are static properties and functions? – When to use them?
-
Strings extensions & tricks: Tips on
String
thanks to custom extensions. -
Swift Concurrency: A file containing playgrounds for Swift Concurrency.
-
@globalActor, GlobalActor & @MainActor: What is a
@globalActor
? – How to create our own@globalActor
thanks to theGlobalActor
protocol? – What is@MainActor
and when should it be used? -
Actor: What is an
actor
? – What problems does it solve? – How and when to use it? – How to constrain protocols so that they can be conformed only by actors? -
Async Let: How to create asynchronous constants with
async let
? – How to make parallel network calls? -
Async await: How to create asynchronous functions with
async await
? – Why is it easier to read and understand asynchronous code? – How to adoptasync await
in an existing project? -
AsyncSequence: What is the purpose of the
AsyncSequence
protocol? – How do you conform to it? -
Sendable, @unchecked Sendable & @Sendable: What is the
Sendable
protocol? – What does it allow to do? – Why use@unchecked Sendable
for classes? – Why and when to use@Sendable
in closures? -
Structured Concurrency: How to execute, cancel and monitor asynchronous operations?
-
-
Swift Updates: A file containing playgrounds for Swift updates.
-
Typealias: What is a
typealias
? – How to create a generictypealias
? -
URLComponents + URLRequest: How to create robust get and post requests?
-
Unit Tests: Which function should be used according to the desired test?
-
init, init?, convenience init, requiered init: How to initialise a
struct
or aclass
withinit
,init?
,convenience init
orrequiered init
? -
private(set): What is
private(set)
? – When and why use it? -
try, throws & rethrows: What are the different ways to call a function that
throws
? – What problem doesrethrows
solve?
- Swift Documentation
- Improve your knowledge of Swift! by Vincent Pradeilles
- Hacking with Swift & What's new in Swift by Paul Hudson
Some playgrounds need to be reworked to provide a better quality. However, if you notice errors or ambiguous passages, do not hesitate to open a PR.
Here's the list:
- ARC & Memory Leaks ∪ ARC, Retain Cycle & Memory Leaks
- init, init?, convenience init, requiered init: add a file for
actor
initialization.
Lucas Abijmil, lucas.abijmil@gmail.com.
You can also reach me on Twitter.