NSSecureCoding Protocol Reference

Conforms to
Available in OS X v10.8 and later.
Declared in


Conforming to the NSSecureCoding protocol 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:

id obj = [decoder decodeObjectForKey:@"myKey"];
if (![obj isKindOfClass:[MyClass class]]) {...fail...}

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 NSSecureCoding:

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 Requirement

Class Methods


Returns whether the class supports secure coding. (required)

+ (BOOL)supportsSecureCoding;
Return Value

Return YES if your class supports secure coding, or NO otherwise.

  • Available in OS X v10.8 and later.
Declared In