Framework
ECore
A pure Swift implementation of https://eclipse.dev/emf/ for Model-Driven Engineering.
Overview
ECore provides a complete implementation of the https://eclipse.dev/emf/ Ecore metamodelling system in pure Swift. Use it to define metamodels, create model instances, and serialise models to XMI or JSON format.
The framework follows the EMF/Ecore specification based on the https://www.omg.org/mof/ standard, providing familiar concepts for developers experienced with Eclipse-based modelling tools whilst offering a modern, type-safe Swift API.
Key Features
-
Metamodelling: Define metamodels using EClass, EAttribute, EReference, and EPackage
-
Dynamic instances: Create model instances at runtime with DynamicEObject
-
XMI serialisation: Load and save models in XMI format using XMIParser
-
JSON serialisation: Alternative JSON format with JSONParser
-
Cross-resource references: Support for models spanning multiple files via ResourceSet
-
Command pattern: Undoable operations with EMFCommand and CommandStack
Quick Example
import ECore
// Load a metamodel from XMI
let parser = XMIParser()
let resource = try await parser.parse(URL(fileURLWithPath: "Company.ecore"))
let package = resource.rootObjects.first as! EPackage
// Find an EClass
let employeeClass = package.eClassifiers.first { $0.name == "Employee" } as! EClass
// Create a dynamic instance
let employee = DynamicEObject(eClass: employeeClass)
employee.eSet("name", value: "Alice")
employee.eSet("salary", value: 50000)
// Save to a new resource
let outputResource = Resource()
outputResource.add(employee)
let serialiser = XMISerializer()
try serialiser.save(resource: outputResource, to: URL(fileURLWithPath: "employees.xmi"))
Topics
Essentials
Learn how to add ECore to your project and create your first metamodel.
Learn the fundamental concepts of the Ecore metamodelling framework.
Core Types
Base protocol for all Ecore model elements.
A dynamic implementation of EObject that stores feature values generically.
A class in the Ecore metamodel.
A package in the Ecore metamodel.
Structural Features
A structural feature (attribute or reference) in the Ecore metamodel.
An attribute in the Ecore metamodel.
A reference in the Ecore metamodel.
Classifiers
A classifier (type) in the Ecore metamodel.
A data type in the Ecore metamodel.
An enumeration type in the Ecore metamodel.
A literal value within an enumeration.
Resources and Serialisation
A resource manages model objects and provides EMF-compliant reference resolution.
A resource set manages multiple resources and enables cross-resource reference resolution.
Parser for XMI (XML Metadata Interchange) files
Serialises EMF objects to XMI (XML Metadata Interchange) format
Parser for JSON files in emfjson/pyecore format
Serializes EMF objects to JSON format (emfjson/pyecore compatible)
Commands and Editing
Protocol defining a command that can be executed, undone, and redone.
Actor managing the execution and undo/redo history of EMF commands.
Actor providing basic editing domain functionality for model modification coordination.
Query and Execution
Core execution engine providing model navigation and query capabilities.
Query framework for ECore models inspired by OCL.
Protocol abstracting model access for transformation engines.
Supporting Types
A factory for creating instances of model elements.
Base protocol for model elements that can have annotations.
Base protocol for model elements that have a name.
Classes
Command to add a value to a many-valued structural feature.
Command that executes multiple commands as a single atomic operation.
Registry for delegates.
Query evaluator that converts string expressions to executable code.
Command to remove a value from a many-valued structural feature.
Command to set a property value on an EObject.
Protocols
Delegate for handling ECore operations.
Delegate for derived feature computation.
Delegate for validating ECore constraints.
An operation in the Ecore metamodel.
Protocol for observing editing domain changes.
Protocol for reference models (metamodels).
Protocol for factories that can create and load resources.
Structures
Performance and usage statistics for command stack operations.
An annotation on a model element.
Metaclass for EAttribute.
The metaclass for EClass.
Simple query parser for basic expressions.
Validation error information.
Metaclass for EDataType.
Metaclass for EEnum.
Metaclass for EEnumLiteral.
Metaclass for EFactory.
Internal storage for feature values in an EObject.
EOperation information for delegate operations.
Metaclass for EPackage.
EParameter information for operation parameters.
Metaclass for EReference.
Default implementation wrapping Resource.
Reference model implementation for EPackages.
Type provider for ECore type operations.
Statistics for editing domain operations.
A proxy representing an unresolved cross-resource reference
Resolves XPath-style fragment identifiers to object IDs
Enumerations
Boolean string representations used in XMI serialisation.
Helper type for resolving EClassifier types from DynamicEObject instances.
Errors that can occur during execution.
Expression types supported by the execution engine.
Wrapper for EcoreValue types in expressions.
Errors that can occur during query parsing.
Errors that can occur during command execution, undo, or redo operations.
Common result types for EMF commands.
The current state of a command in its lifecycle.
Helper type for resolving EStructuralFeature types from DynamicEObject instances.
Ecore metamodel classifier names.
Ecore built-in data type names.
URI constants for Ecore built-in types and namespaces.
Events that can occur in an editing domain.
Standardised error messages for Ecore operations.
Errors that can occur during JSON parsing
Errors that can occur during JSON serialization
Logging categories for structured logging in Ecore operations.
XMI attribute names used in Ecore metamodel serialisation.
XMI element names used in Ecore metamodel structure.
Errors that can occur during XMI parsing
XML namespace attribute names used in document parsing.