Is there a weak Set type?

I have some UIViews that I want to associate with a boolean value. I could use a set...

 var isFoo: Set<UIView>

So for any given UIView, my bool value is "true" if the view is in the set. But I don't want the Set retaining views that would otherwise be deallocated. Is there a standard way to do something like this?

Maybe this WeakBox could hold a second field for the raw pointer, and use that for implementing Hashable and Equatable, so at least it wouldn't change while in the Set.

The Set would need to be periodically cleaned of zombie values.

I was trying to attach some properties to UIViews, sort of like "extension properties". I may end up creating a subclass of UIView that wraps one other UIView along with the properties. Or use some old Objective-C API that might be able to attach key/value pairs to UIViews.

As mentioned, there is no standard way. I made something a long time ago for my use case. It is not exactly what you need, but you might find it useful. I have not tested it with the current version of Swift, but I think it should probably work as is. You can just paste it in a playground and see what happens.

As Nikita says, a subclass may be your best bet.

Maybe the (untested) solution I suggested for Hashing Weak
Variables

will help?

Dave