当 NSDictionary 不知道它是未来的内容时,它如何支持 NSSecureCoding

How can NSDictionary support NSSecureCoding, when it doesn't know it's future content

根据 Apple 规范,当 class 支持 NSSecureCoding 时,它应该使用

decodeObjectOfClass:forKey:

里面是initWithCoder

但由于字典对其内容一无所知,它如何支持安全编码?

与自定义对象相反,其中 属性 class 是已知的

Foundation 容器(Array、Dictionary、Set 等……?)并不像人们想象的那么安全。显然只有已知的基础 类 被认为是安全的,这意味着默认实现在使用 NSSecureCoding 时不允许存储自定义对象。

最重要的引述:

[...] if you use NSArray() or other collection classes directly in your coding, you need to check what you got back. They are ‘securely’ decoded to the extent that Apple believes decoding them will not result in a buffer overflow etc, that’s all you get by default. [...]