Documentation Language: Swift

Class

EMFCommand

Protocol defining a command that can be executed, undone, and redone.

@MainActor class EMFCommand

Overview

EMF commands encapsulate model modifications in a reversible manner, enabling undo/redo functionality and transactional operations. Commands follow the Command pattern, providing a uniform interface for all model modifications.

Overview

Commands represent atomic operations on model elements that can be:

All commands must be thread-safe and work correctly in concurrent environments. The execution model ensures that command operations are serialised through actors to maintain model consistency.

Command Lifecycle

  1. Creation: Command is created with necessary context

  2. Execution: execute() is called to apply changes

  3. Undo: undo() reverses the changes (optional)

  4. Redo: redo() re-applies the changes after undo (optional)

Example Usage

let command = SetCommand(
    object: person,
    feature: nameAttribute,
    value: "John Doe"
)

let result = try await command.execute()
try await command.undo()    // Reverses the change
try await command.redo()    // Re-applies the change

Subclassing

Concrete commands should inherit from this base class and override the necessary methods. The base class provides default implementations that can be overridden as needed.

Topics

Initializers

?
init()

Initialise a new command.

Instance Properties

V
canRedo

Indicates whether the command can be redone after being undone.

V
canUndo

Indicates whether the command can be undone.

V
description

A human-readable description of the command.

Instance Methods

F
execute()

Execute the command, applying its changes to the model.

F
redo()

Redo the command, re-applying its changes after undo.

F
undo()

Undo the command, reversing its changes to the model.

Relationships

Inherited By

Conforms To

See Also

Commands and Editing

C
CommandStack

Actor managing the execution and undo/redo history of EMF commands.

C
BasicEditingDomain

Actor providing basic editing domain functionality for model modification coordination.