NSSecureCoding Protocol Reference
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in OS X v10.8 and later. |
| Declared in | NSObject.h |
Overview
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:
An object that does not override
initWithCoder:can conform toNSSecureCodingwithout any changes (assuming that it is a subclass of another class that conforms).An object that does override
initWithCoder:must decode any enclosed objects using thedecodeObjectOfClass:forKey:method. For example:id obj = [decoder decodeObjectOfClass:[MyClass class]
forKey:@"myKey"];
In addition, the class must override its
supportsSecureCodingmethod to returnYES.
For more information about how this relates to the NSXPC API, see “Creating XPC Services” in Daemons and Services Programming Guide.
Class Methods
supportsSecureCoding
Returns whether the class supports secure coding. (required)
Return Value
Return YES if your class supports secure coding, or NO otherwise.
Availability
- Available in OS X v10.8 and later.
Declared In
NSObject.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-12-13)