-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-iOS: new WWDC23 video {'Generalize APIs with parameter packs'}.
- Loading branch information
Showing
13 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title : "Generalize APIs with parameter packs" | ||
abstract: "Abstract over types as well as the number of arguments in generic code." | ||
|
||
displayToc: true | ||
--- | ||
|
||
# WWDC 2023: Generalize APIs with parameter packs | ||
Find hereafter a detailed summary of a video that belongs to a [taxonomy of some WWDC footages](../../). | ||
|
||
The original video is available on the **Apple official website** ([session 10168](https://developer.apple.com/videos/play/wwdc2023/10168/)). | ||
![](../../../../../images/iOSdev/wwdc23-10168_Poster.png) | ||
"Swift parameter packs are a powerful tool to expand what is possible in your generic code while also enabling you to simplify common generic patterns. We'll show you how to **abstract over types as well as the number of arguments in generic code** and simplify common generic patterns to avoid overloads." | ||
</br>Hereafter, the underlined elements lead directly to the playback of the WWDC video at the appropriate moment. | ||
</br> | ||
|
||
## [The origins](https://developer.apple.com/videos/play/wwdc2023/10168/?time=51) | ||
![](../../../../../images/iOSdev/wwdc23-10168_1.png) | ||
|
||
Regarding a [client server example](https://developer.apple.com/videos/play/wwdc2023/10168/?time=124), the number of query arguments may be too large according to the needs. | ||
|
||
![](../../../../../images/iOSdev/wwdc23-10168_2.png) | ||
|
||
However, this problem might be partially solved while using the [variadic parameters](https://developer.apple.com/videos/play/wwdc2023/10168?time=136) combined with the [type erasure](https://developer.apple.com/videos/play/wwdc2023/10168?time=172) notion that give rise to some [limitations](https://developer.apple.com/videos/play/wwdc2023/10168?time=154) though. | ||
|
||
![](../../../../../images/iOSdev/wwdc23-10168_3.png) | ||
This kind of situation is typically what **[parameter packs](https://developer.apple.com/videos/play/wwdc2023/10168?time=237)** are for. | ||
</br> | ||
|
||
## [The fundamentals](https://developer.apple.com/videos/play/wwdc2023/10168/?time=248) | ||
|
||
'A **parameter pack** can hold any quantity of types or values and pack them together to pass them as an argument to a function.' | ||
![](../../../../../images/iOSdev/wwdc23-10168_4.png) | ||
|
||
Handling packs at the **type-level** is a [major difference](https://developer.apple.com/videos/play/wwdc2023/10168/?time=358) with the usual collections thanks to new ways for [writing code](https://developer.apple.com/videos/play/wwdc2023/10168/?time=376). | ||
|
||
![](../../../../../images/iOSdev/wwdc23-10168_5.png) | ||
|
||
It comes in handy to [avoid boilerplate code](https://developer.apple.com/videos/play/wwdc2023/10168/?time=513) in such situations... | ||
![](../../../../../images/iOSdev/wwdc23-10168_6.png) | ||
|
||
...while easily tailoring the [generic requirements](https://developer.apple.com/videos/play/wwdc2023/10168/?time=655) on packs as well. | ||
![](../../../../../images/iOSdev/wwdc23-10168_7.png) | ||
</br> | ||
|
||
## [Implementation](https://developer.apple.com/videos/play/wwdc2023/10168/?time=732) | ||
It's recommended the **parentheses be used** for wrapping the pattern expression when the results are embedded in a tuple. | ||
|
||
![](../../../../../images/iOSdev/wwdc23-10168_8.png) | ||
|
||
Regarding the [initial example](#the-origins), if the **[input and output types need to be different](https://developer.apple.com/videos/play/wwdc2023/10168/?time=871)**, the code writing may be changed to tailor the parameter pack concept while improving the [flow control](https://developer.apple.com/videos/play/wwdc2023/10168/?time=1013) with the `do-catch` statement for **handling errors**. | ||
|
||
![](../../../../../images/iOSdev/wwdc23-10168_9.png) | ||
|
||
</br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters