When do we REALLY need to use [weak self]? 🤔
HTML-код
- Опубликовано: 8 сен 2024
- #iOS #swift #softwaredeveloper #iosdeveloper
Thank you for watching this video 🙌
Get the code 👉 bit.ly/3tVujfp
➜ Leave a tip: www.buymeacoff...
➜ Website: www.swiftwithv...
➜ Twitter: / v_pradeilles
➜ GitHub: github.com/vin...
➜ LinkedIn: / vincentpradeilles
Did you find this explanation useful? Do you think of a situation that doesn't fit in my three examples? Let me know in the comments 🚀
Hi, good video, what do you think of the use of "unowned", in the 3rd example it can be relevant sometimes to use it, it avoids an unnecessary guard let when you know that if the closure is called self still exists
@@jeremymagnier good question! There’ll actually be a video on this exact topic later this month 🤫
@@v_pradeilles I activate the bell so haha
Good example. It will be good if we can have part 2 representing the retain cycle in memory graph
In regards to the 2nd example, leaving a strong reference to self would be a poor decision for the simple reason that the behavior isn't explicit and is therefore not communicated. If I saw this in a codebase I would refactor to a clearer solution. Leaving a strong reference to self is one of those things that may be a shortcut, but will immediately incur technical debt on your codebase.
That being said, great video! Loved the examples.
Could you also consider an example with multiple nested closures and explain where we need to specify weak self to avoid retain cycles.
Great question! I've actually already covered this topic in a separate video: ruclips.net/video/2Ot86h_Xu1M/видео.html
really useful content. your videos have been extremely useful for my iOS interview questions thx!
Oh!! It's really useful! I am a student studying iOS in South Korea.
So I wanted to translate it to Korean and post it on my blog to make more people see it
(I am not using it to make any profit! & I'll put a link to the original video in my post.) is it OK?
good example, thank you for sharing
This still makes my head hurt :). I wish the compiler could just figure it out for all cases and create a warning/error.
Thanks for the explanation. It's very useful.
Great topic! Another good topic would be when to use unowned. For example in your 3rd example I think unowned would be perfect because when self is deinited handler will also be removed.
The video on that exact topic is coming later this month 😉
I’d say it’s only required in the 3rd example
For second example I am trying to crash app without weak self by poping back view controller or making reference nil but its always capturing self and not crashing is it because apple created it ? for our clousres we need to add [weak self ] which escapes ?
thank you for your clip, I've learned something new today, it's helpful, much appreciated, and also I want to ask a simple question:
do we need to use [weak self] in case of present AlertController or any animation (any code to use in animation: { } ) ?
Very informative video vincent, so with closure at line 27 there would not be a memory leak is it correct? There is no reference to the closure, and so, there is no retain to self.
But diving a bit deeper:
1)There would be a kind of retain to self anyway, as that closure executes after 2 seconds, even if the ViewModel gets deallocated. Correct?
2) The ViewModel can't get deallocated, until the DispatchQueue.after is executed. Correct?
AÏE LIKE YOURE FRENCH ACCENTE. GOUD VIDEO ALRIGHT