I have a function below:
func check(_ type: Any.Type) {
switch type {
case is [String].Type
...
}
}
For example:
class TaskContainer: Codable {
let id: String
let tasks: [String]
}
typealias TaskContainers = [TaskContainer]
check(TaskContainers.self)
How to check if an array is Codable?
Not working:
- case is [Codable].Type
- case is Array[Codable].Type
[TaskContainer].Typeis a subtype of[Codable].Type, but it is not. What you are trying to do is highly unusual. If you tell us more about why you want to do this, maybe we can suggest a better way.Any.Typeat all suggests a very deep type problem in your code. You should back up and think through the problem you're actually trying to solve, and we should be able to help you.check. Edit your question to show us how you're trying to use the library and what errors are occurring.