What you say make sense if the mutated value is used afterward. But for an JSONEncoder
:
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .custom { date, encoder in
var container = encoder.singleValueContainer()
try container.encode(date.formatted(.iso8601)) // what happen here?
// nothing more
// the code read like none sense, illogical :(
}
My guess is inside container
it's "wired" so calling .encode(...)
cause the change up in the encoder
. So why would a "caller" need to use an intermediate var
? Seems like unnecessary leaking of implementation details.