I am reading through the Encoding and Decoding Custom Types article, and I am seeing to encoder: Encoder and from decoder: Decoder throughout the examples.
I am new to Swift, and it isn't really clear to me why it is to encoder: Encoder and not just encoder: Encoder.
Here is a longer snippet for more context:
extension Coordinate: Encodable {
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(latitude, forKey: .latitude)
try container.encode(longitude, forKey: .longitude)
var additionalInfo = container.nestedContainer(keyedBy: AdditionalInfoKeys.self, forKey: .additionalInfo)
try additionalInfo.encode(elevation, forKey: .elevation)
}
}
What is the purpose of to and from within these examples?
I have been trying to find an answer to this question, but searching for "what is the purpose of to in swift" and other variants has been remarkably unsuccessful.