[swift-users] KeyedDecodingContainerProtocol decode methods non-mutating?

Brent Royal-Gordon brent at architechies.com
Sun Dec 31 03:16:33 CST 2017


> On Dec 28, 2017, at 1:57 PM, Ingo Maier via swift-users <swift-users at swift.org> wrote:
> 
> Can anybody tell why the decode methods in UnkeyedDecodingContainer
> are marked mutating but those in KeyedDecodingContainerProtocol and
> SingleValueDecodingContainer are not? Is it a simple oversight or is
> there a reason for this? It seems to me that all of them should be
> mutating.


The `UnkeyedDecodingContainer.decode(_:)` methods consume values as they decode them; that is, the first call returns the first value, the second call returns the second value, etc. The ones in the other containers don't consume values; in theory, you could decode the same key twice and you should get the same value both times. So the UnkeyedDecodingContainer methods are mutating, but the other containers' methods are not.

-- 
Brent Royal-Gordon
Architechies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171231/3f218c9f/attachment.html>


More information about the swift-users mailing list