When do we REALLY need to use [weak self]? 🤔

  Рет қаралды 7,586

Vincent Pradeilles

Vincent Pradeilles

2 жыл бұрын

#iOS #swift #softwaredeveloper #iosdeveloper
Thank you for watching this video 🙌
Get the code 👉 bit.ly/3tVujfp
➜ Leave a tip: www.buymeacoffee.com/v.pradei...
➜ Website: www.swiftwithvincent.com
➜ Twitter: / v_pradeilles
➜ GitHub: github.com/vincent-pradeilles/
➜ LinkedIn: / vincentpradeilles

Пікірлер: 22
@v_pradeilles
@v_pradeilles 2 жыл бұрын
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 🚀
@jeremymagnier
@jeremymagnier 2 жыл бұрын
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
@v_pradeilles
@v_pradeilles 2 жыл бұрын
@@jeremymagnier good question! There’ll actually be a video on this exact topic later this month 🤫
@jeremymagnier
@jeremymagnier 2 жыл бұрын
@@v_pradeilles I activate the bell so haha
@ShubhamGupta-qo2pt
@ShubhamGupta-qo2pt 2 жыл бұрын
Good example. It will be good if we can have part 2 representing the retain cycle in memory graph
@KEVINKIM2586
@KEVINKIM2586 2 жыл бұрын
really useful content. your videos have been extremely useful for my iOS interview questions thx!
@captaintech8337
@captaintech8337 2 жыл бұрын
Thanks for the explanation. It's very useful.
@rasheshbosamiya1482
@rasheshbosamiya1482 2 жыл бұрын
good example, thank you for sharing
@webdavis
@webdavis 2 жыл бұрын
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.
@Noah-qm4ki
@Noah-qm4ki 2 жыл бұрын
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?
@anhhanry7167
@anhhanry7167 Жыл бұрын
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: { } ) ?
@ronnyfenrich
@ronnyfenrich 2 жыл бұрын
This still makes my head hurt :). I wish the compiler could just figure it out for all cases and create a warning/error.
@michaelvoline6205
@michaelvoline6205 4 ай бұрын
Could you also consider an example with multiple nested closures and explain where we need to specify weak self to avoid retain cycles.
@v_pradeilles
@v_pradeilles 4 ай бұрын
Great question! I've actually already covered this topic in a separate video: kzfaq.info/get/bejne/aLWka5mZxL7ZYYE.html
@salmansiddiqui9522
@salmansiddiqui9522 2 жыл бұрын
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 ?
@developerios6096
@developerios6096 Жыл бұрын
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?
@MrWvid
@MrWvid 2 жыл бұрын
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.
@v_pradeilles
@v_pradeilles 2 жыл бұрын
The video on that exact topic is coming later this month 😉
@poluxsaurus1454
@poluxsaurus1454 2 жыл бұрын
I’d say it’s only required in the 3rd example
@Herton17
@Herton17 4 ай бұрын
AÏE LIKE YOURE FRENCH ACCENTE. GOUD VIDEO ALRIGHT
When is it RISKY to use [unowned self] inside a closure? 🤨
7:31
Vincent Pradeilles
Рет қаралды 1,8 М.
No more [weak self] 🤯 (special video for the 1,000 subscribers)
13:35
Vincent Pradeilles
Рет қаралды 7 М.
Опасность фирменной зарядки Apple
00:57
SuperCrastan
Рет қаралды 12 МЛН
Spot The Fake Animal For $10,000
00:40
MrBeast
Рет қаралды 196 МЛН
Amazing weight loss transformation !! 😱😱
00:24
Tibo InShape
Рет қаралды 67 МЛН
Difference between weak and unowned in Swift
16:20
Code Cat
Рет қаралды 14 М.
Weak and Unowned Self Closure Memory Leak Fixes
12:21
Lets Build That App
Рет қаралды 56 М.
MVVM vs MVP: what's the difference? 🤔
9:27
Vincent Pradeilles
Рет қаралды 9 М.
How to use weak self in Swift | Continued Learning #18
20:33
Swiftful Thinking
Рет қаралды 17 М.
How to implement Dependency Injection in Swift!
12:56
Vincent Pradeilles
Рет қаралды 13 М.
3 MISTAKES to avoid when using Async / Await in Swift 😌
4:41
Vincent Pradeilles
Рет қаралды 10 М.
Strong vs. Weak Swift 5: What is Weak Self (Xcode 11, 2020)
16:41
How to implement the MVVM architecture in Swift!
8:33
Vincent Pradeilles
Рет қаралды 9 М.
Проверил, как вам?
0:58
Коннор
Рет қаралды 390 М.
Как противодействовать FPV дронам
44:34
Стратег Диванного Легиона
Рет қаралды 117 М.
Хакер взломал компьютер с USB кабеля. Кевин Митник.
0:58
Последний Оплот Безопасности
Рет қаралды 2,3 МЛН
Better Than Smart Phones☠️🤯 | #trollface
0:11
Not Sanu Moments
Рет қаралды 19 МЛН