Sitemap
Better Programming

Advice for programmers.

Member-only story

A Better Way To Test Reference Cycles in iOS

6 min readJan 15, 2023

--

Photo by Alessio Soggetti on Unsplash

Testing is one of my favorite topics, that’s no news. And I love to research and find new ways to improve how we can testing our apps and libraries.

One of the hardest things to test in iOS are reference cycles. I already wrote about testing reference cycles a year and a half ago, but that solution was not completely satisfying: it forced to pollute production code with closures and observers.

Recently,

resuscitated that post with other suggestions on how to achieve a similar result. I’m very grateful for those suggestions as I love to discuss these topics with the iOS community, but they both suffered from the same issue: they require adding overhead code for the sake of testing. Yes, you can compile them out using precompiler pragmas like #if DEBUG but they will still make the code less readable.

Last year, thanks also to

, I learned a different, polished way to test reference cycles and today I want to share it with everyone.

What’s a Reference Cycle?

--

--

Riccardo Cipolleschi
Riccardo Cipolleschi

Written by Riccardo Cipolleschi

Hey there, I’m Riccardo. Software engineer at Meta. I have a passion for iOS and I love to share my knowledge with others.

Responses (1)