Curious, why I'm getting this error:
If I declare that only objects can conform to the protocol:
public protocol DayViewStateUpdating: AnyObject {
func move(from oldDate: Date, to newDate: Date)
}
And then trying to instantiate an NSHashTable
of that protocol:
private var clientsHashTable = NSHashTable<DayViewStateUpdating>.weakObjects()
I'm getting the error:
'NSHashTable' requires that 'any DayViewStateUpdating' be a class type
But the any DayViewStateUpdating is guaranteed to be a class type, as it's declared as AnyObject earlier. Or am I missing something?
Source code of the file in context: DayViewState
NSHashTable
is expecting Objective-C style protocols, rather than Swift-style protocol existentials.Marking your protocol as
@objc protocol DayViewStateUpdating
works.But really, you can get away without needing
NSHashTable
here, by using aWeak
wrapper like so: