I'm extensively using KVC to build unified interface for the needs of an app. For instance, one of my functions gets an object, which undergoes several checks based solely on dictionary of string keys.
Thus I need a way to check if an object by the key is of collection type.
I expected to have been able to make some protocol check (like IEnumerable in C# to check if it can be enumerated), but it didn't work out:
if let refCollection = kvcEntity.value(forKey: refListLocalKey) as? AnySequence<CKEntity> { ... }
I tried AnyCollection, too.
I know I could iterate all main collection types, by simply typing:
if let a = b as? Set { ...} // (or: if a is Set {...})
if let a = b as? Array { ...}
if let a = b as? Dictionary { ...}
But this doesn't seem proper from inheritance/polymorphism point of view.