Software Dev

Everything you need to know about [weak self]

This is a post about the idea of “weak self” in the Swift programming language. It is not a post about self-doubt. You are strong. 💪😉

But your Swift object might be weak, or at least @escaping and weakly held. 🤷🏻‍♂️ If this makes no sense, maybe it’s time to check out some pictures or quotes.

If you’re a Swift programmer, you probably know from experience that if you need a reference back to the calling self in a closure, and that closure might last longer than self, then you should send that closure yourself as [weak self] so you don’t end up with a retain cycle and a memory leak.

Still, it can get a bit confusing. What do you do if the weak self is actually gone when you execute the closure? Can the weak self disappear in the middle of the closure?

Fortunately, the Swift blogger Christian Tietze has all the answers. Or at least he has found some answers and summarized them nicely.

In the end, it all points to Chris Downie’s rules of thumb.

  • Only use a strong self for non-@escaping closures (ideally, omit it & trust the compiler)
  • Use weak self if you’re not sure
  • Upgrade self to a strongly-retained self at the top of your closure.

See also: When to use weak self and why to learn more about the capture list, of which [weak self] is part.

Via iOS Dev Weekly.

You

The Spacing Effect: Forgetting Makes It Stick

I love this simple idea about learning: information sticks better if you learn it in smaller chunks over time and forget a little bit in between.

It’s the exact opposite of cramming like we did in college. 😆

👉 Teach Yourself How to Learn Better

As it turns out, forgetting the information for a while helps makes it stick for longer if you revisit it later. 🤯. It may seem odd, but it make sense.

If you force your brain to bring back knowledge it’s starting to forget, then it puts a sticker to remind itself it shouldn’t forget.

This same idea came up here a few months ago in a different post. And seeing it again now, fittingly enough, really solidifies the concept for me. 🙃

Me · You

The 50/50 Rule and Why I Blog

My blog’s current tag line is “This is not a blog.”

Originally, this site was intended as a way to keep track of links to interesting or useful things, like glorified bookmarks. But since then, it has evolved to serve another purpose: to make me think and communicate about stuff.

See, as I was bookmarking stuff, I found myself adding little bits about why I liked the link or context about how I found it. Over time, I found that when I would link to an article, I would sometimes want to add a summary about the article to help me process it and remember it better.

A better way to learn, process, retain and remember information is to learn half the time, and share half the time.

If I take two seconds to effortlessly save a bookmark, then the information is saved and soon forgotten. If I add even a quick post about it, giving it a title and some context or a summary, then that post is now a part of me. And as a bonus, I get to share it with other people.

So I was happy to see this article, which makes me think I am not wasting my time.

👉 The 50/50 Rule (How to Retain And Remember 90% of Everything You Learn)

It basically says that if you make yourself talk about something, then you come to understand it or appreciate it better. Spend half you time learning and half your time explaining what you learned.

According to the article, I would be serving myself better by writing out my notes by hand. It seems people type too fast for their brain to absorb what they’re doing. And simply by writing that, I now remember that fact. But I’m typing this anyways because you can’t tag, search, and share your paper notebook. 🤷🏻‍♂️

And yes, this article is so meta.