A protocol that indicates that an object handles encoding and decoding instances of itself in a manner that is robust against object substitution attacks.


Historically, many classes decoded instances of themselves like this:

if let object = decoder.decodeObjectForKey("myKey") as MyClass {
    // ...succeeds...
} else {

This technique is potentially unsafe because by the time you can verify the class type, the object has already been constructed, and if this is part of a collection class, potentially inserted into an object graph.

In order to conform to NSSecure​Coding:

For more information about how this relates to the NSXPC API, see Creating XPC Services in Daemons and Services Programming Guide.


Checking for Secure Coding

static var supports​Secure​Coding:​ Bool

A Boolean value that indicates whether or not the class supports secure coding.


Inherits From

Adopted By