检查数组是否编码



我具有下面的功能:

func check(_ type: Any.Type) {
        switch type {
           case is [String].Type
        ...
      }
}

例如:

class TaskContainer: Codable {
    let id: String
    let tasks: [String]
}
typealias TaskContainers = [TaskContainer]
check(TaskContainers.self)

如何检查数组是否编码?

不工作:

  • 案例是[Codable] .Type
  • 案例是数组[Codable] .Type

我不确定检查的原因,但这应该起作用。

if let _ = TaskContainers.self as? Codable.Type {
    // Conforms to Codable protocol.
}

最新更新