user3166661
user3166661

Reputation: 27

Check if array is Codable

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

Answers (1)

Hamer
Hamer

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

Related Questions