Reputation: 27
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:
Upvotes: 0
Views: 384
Reputation: 1383
I'm not sure the reason for checking but this should work.
if let _ = TaskContainers.self as? Codable.Type {
// Conforms to Codable protocol.
}
Upvotes: 1