Alcivanio (Swift)
1 min readFeb 25, 2020

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!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Alcivanio (Swift)
Alcivanio (Swift)

Written by Alcivanio (Swift)

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

No responses yet

Write a response