For an example struct Person
that is to be serialized:
struct Person {
let firstName: String
let lastName: String
}
We could make it conform to the Encodable
, Decodable
or Codable
protocols. I understand that our choice between Encodable
and Decodable
is contingent on the use case, (for example if we are hitting an API and do not need to decode a response containing the same type) but we could also make it conform to Codable
if the struct is to be both used for encoding and decoding.
If we need the struct strictly for encoding or decoding, but not both, is it a bad idea from a performance perspective to just use a catch-all Codable
instead of specifying Encodable
/Decodable
conformance?
An obvious disadvantage of using Codable
instead of specifying Encodable
/Decodable
is that another programmer may misconstrue the struct as being used for encoding and decoding, when in reality only one of the two is happening. But what if I am strictly interested in performance?