The base protocol for extensible file format support in Model I/O.


protocol MDLComponent


By extending this protocol in your own custom protocols, you can define new functionality to add to the MDLObject instances in the object graph corresponding to a MDLAsset instance.

Model I/O adopts this pattern to support container objects (with the MDLObjectContainerComponent protocol) and objects with associated transformations (with the MDLTransformComponent protocol). To work with these aspects of a Model I/O object, call the object’s componentConforming(to:) method with the appropriate protocol. (The MDLObject class also provides convenience methods and properties for accessing features of these components without directly accessing the component instances.)

To add your own object features, first define a protocol that extends the MDLComponent protocol, implement a class that adopts that protocol, and then use the setComponent(_:for:) method to add your component to each object that needs it. The example below shows how you might implement a file format that associates scripting event triggers with parts of a game scene.

@protocol MyScriptTriggerComponent <MDLComponent>
// key: trigger identifier, value: scripting-language code
@property NSDictionary<NSString *, NSString *> *scriptTriggers;
@interface MyScriptTriggerStorage <MyScriptTriggerComponent>
@property NSDictionary<NSString *, NSString *> *scriptTriggers;
@implementation MDLObject (MyScriptTriggers)
- (void)setScriptTriggers:(NSDictionary<NSString *, NSString *>)triggers {
    MyScriptTriggerStorage *storage = [self componentConformingToProtocol:@protocol(MyScriptTriggerComponent)];
    if (storage == nil) {
        storage = // ... allocate / manage storage ...
        [self setComponent:storage forProtocol:@protocol(MyScriptTriggerComponent)];
    storage.scriptTriggers = triggers;

See Also

Extensible Asset Format Support

class MDLObjectContainer

A default implementation for handling object hierarchy relationships in a 3D asset.

protocol MDLObjectContainerComponent

The general interface for classes that can act as containers in an object hierarchy.

protocol MDLTransformComponent

The general interface for classes that manage local coordinate space transforms for 3D objects