Hello David, thanks for reaching out.

Let's go over the list of problems you have found:

  1. Basically just objects can have weak references, so we have to somehow say that out `T` is a object. You can do it easily by restricting the type like T: AnyObject. You have to apply it to the protocol and to the WeakReference object too. Something interesting would be to say that the protocol is of @objc too, it will let the compiler happy;
  2. Basically what we're trying to do here is to check if that object is already in the list. You can solve it by adding an ID to the protocol, so each object will have a different unique ID. Or you can say that you object will be a type of object that conforms to Equatable.
  3. You got it! Just add value to the call of the initializer.

Thanks again for leaving a comment. I updated the Gists in the post. Let me know if it's working on your side!

Computer Engineer + iOS Engineer. I am interested in Swift, Kotlin, Firebase, Data Structures, ASO & On Solving Real World Problems.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store