Task and self capture
After moving to Swift Concurrency, your team is arguing about whether you always need [weak self] inside Task { }. When is it unnecessary, and in which Tasks is it required?
After moving to Swift Concurrency, your team is arguing about whether you always need [weak self] inside Task { }. When is it unnecessary, and in which Tasks is it required?
A Task isn't a cycle unless self holds the Task; it only extends self's lifetime for the duration of the work, so weak isn't required. A long-running or infinite-stream Task keeps self alive after the screen closes and needs weak self, and if you store the Task handle in a property of self, that's a real cycle and weak is mandatory.
ConcurrencyShort answerBasics
When the user enters the detail screen, it calls an API like this and shows the data. ……
#task #weak-self #cancellation
Memory and ARCMultiple choiceBasics
Which of these two snippets creates a reference cycle? …
#weak-self #capture
ConcurrencyShort answerBasics
In Swift Concurrency, when you create a Task { }, when and where does that code run?
#task #cancellation
ConcurrencyMultiple choiceExpert
In this Swift Concurrency code, which statement about what actually happens right after…
#task #cancellation