I'm using Swift 2 and using WeakContainer as a way to store a set of weak objects, much like NSHashTable.weakObjectsHashTable()
struct WeakContainer<T: AnyObject> {
weak var value: T?
}
public protocol MyDelegate : AnyObject {
}
Then in my ViewController, I declare
public var delegates = [WeakContainer<MyDelegate>]
But it is error
Using MyDelegate as a concrete type conforming to protocol AnyObject is not supported
I see that the error is that WeakContainer
has value
member declared as weak
, so T
is expected to be object. But I also declare MyDelegate
as AnyObject
, too. How to get around this?
NSHashTable
? – TelegaAnyObject
toclass
, it should work fine. Don't ask me to explain the difference though. – Telegapublic protocol MyDelegate : class
before, it does not work – CholecystitisNSHashTable
is not generic, I don't want that – Cholecystitisclass
andAnyObject
should be the same thing – Mucin