How to null weak links in non-ARC?

I do not like ARC.

But the most important feature of ARC, nullifying a weak link, is missing in non-ARC. I am currently using MAZeroingWeakRef , it works, but is hacked, sometimes making codes redundant. Any other ways to nullify weak links?

+4
source share
2 answers

Implementing nulling weak links is not difficult. All you have to do is just keep track of all the link pointers - store them in a collection - and assign NULL when deleting the pointer object. In any case, doing all this manually is really a lot of work, you literally need to write all the manual tracking code to be effective enough in Objective-C.

And in the end, you will finally find that you need an automatic machine for writing code - a static compiler - and this is exactly what ARC does. You can implement something like ARC yourself. But if I tell you, I just use an existing, reliable, stable, well-designed and supported compiler implementation.

Also, without following Apple, this is not reasonable behavior if you want to develop Apple stuff. Unlike other platform holders such as Microsoft, Apple does not care about maintaining backward compatibility. If they don’t think that something is good, it will become obsolete and deleted in the end - for example, Objective-C GC.

+1
source

I think you should adhere to the paradigm that Apple itself recommended before ARC was introduced, i.e. omitted all your weak links from the -dealloc method. This is not only a de facto standard, but also the way that the Xcode code refactor behaves when ARC is not enabled, so matching it should save a couple of headaches.

0
source

Source: https://habr.com/ru/post/1414371/


All Articles