NSClass​Description is an abstract class that provides the interface for querying the relationships and properties of a class. Concrete subclasses of NSClass​Description provide the available attributes of objects of a particular class and the relationships between that class and other classes. Defining these relationships between classes allows for more intelligent and flexible manipulation of objects with key-value coding.


It is important to note that there are no class descriptions by default. To use NSClass​Description objects in your code you have to implement them for your model classes. For all concrete subclasses, you must provide implementations for all instance methods of NSClass​Description. (NSClass​Description provides only the implementation for the class methods that maintain the cache of registered class descriptions.) Once created, you must register a class description with the NSClass​Description method register(_:​for:​).

You can use the NSString objects in the arrays returned by methods such as attribute​Keys and to​Many​Relationship​Keys to access—using key-value coding—the properties of an instance of the class to which a class description object corresponds. For more about attributes and relationships, see Cocoa Fundamentals Guide. For more about key-value coding, see Key-Value Coding Programming Guide.

NSScript​Class​Description, which is used to map the relationships between scriptable classes, is the only concrete subclass of NSClass​Description provided as part of the Cocoa framework.


Working with class descriptions

init?(for:​ Any​Class)

Returns the class description for a given class.

class func invalidate​Class​Description​Cache()

Removes all NSClass​Description objects from the cache.

class func register(NSClass​Description, for:​ Any​Class)

Registers an NSClass​Description object for a given class in the NSClass​Description cache.

Attribute keys

var attribute​Keys:​ [String]

Overridden by subclasses to return the names of attributes of instances of the described class.

Relationship keys

func inverse(for​Relationship​Key:​ String)

Overridden by subclasses to return the name of the inverse relationship from a relationship specified by a given key.

var to​Many​Relationship​Keys:​ [String]

Overridden by subclasses to return the keys for the to-many relationship properties of instances of the described class.

var to​One​Relationship​Keys:​ [String]

Overridden by subclasses to return the keys for the to-one relationship properties of instances of the described class.


static let NSClass​Description​Needed​For​Class:​ NSNotification.Name

Posted by init(for:​) when a class description cannot be found for a class.


Inherits From