I use KVC extensively to create a unified interface for the needs of the application. For example, one of my functions receives an object that undergoes several checks based solely on the dictionary of string keys.
So I need a way to check if an object is a collection type key.
I expected to be able to do some protocol checking (e.g. IEnumerable in C # to check if it can be enumerated), but that didn't work:
if let refCollection = kvcEntity.value(forKey: refListLocalKey) as? AnySequence<CKEntity> { ... }
I also tried AnyCollection.
I know that I could iterate over all the basic types of collections by simply typing:
if let a = b as? Set { ...}
if let a = b as? Array { ...}
if let a = b as? Dictionary { ...}
But this does not seem correct in terms of inheritance / polymorphism.