A pure Swift implementation of the Eclipse Modelling Framework (EMF) Ecore metamodel for macOS, Linux, and Windows.
- Pure Swift: No Java/EMF dependencies, Swift 6.2+ with strict concurrency
- Cross-Platform: Full support for macOS and Linux
- Value Types: Sendable structs and enums for thread safety
- BigInt Support: Full arbitrary-precision integer support via swift-numerics
- Complete Metamodel: EClass, EAttribute, EReference, EPackage, EEnum, EDataType
- Resource Infrastructure: EMF-compliant object management and ID-based reference resolution
- JSON Serialisation: Load and save JSON models with full round-trip support
- Bidirectional References: Automatic opposite reference management across resources
- XMI Parsing: Load .ecore metamodels and .xmi instance files
- Dynamic Attribute Parsing: Arbitrary XML attributes with automatic type inference (Int, Double, Bool, String)
- XPath Reference Resolution: Same-resource references with XPath-style navigation (//@feature.index)
- XMI Serialisation: Write models to XMI format with full round-trip support
- Swift 6.0 or later
- macOS 15.0+ or Linux (macOS 15.0+ required for SwiftXML dependency)
# Build the library
swift build
# Run tests
swift testThe library implements the core of the Eclipse Modelling Framework and
can be included in other libraries, tools, and utilities (see the documentation).
For practical use, the swift-ecore command-line tool from the
swift-modelling repository
provides comprehensive Eclipse Modelling Framework functionality for Swift.
- SPM package structure
- Primitive type mappings (EString, EInt, EBoolean, EBigInt, etc.)
- BigInt support via swift-numerics
- Type conversion utilities
- 100% test coverage for primitive types
- EObject protocol
- EModelElement (annotations)
- ENamedElement
- EClassifier hierarchy (EDataType, EEnum, EEnumLiteral)
- EClass with structural features
- EStructuralFeature (EAttribute and EReference with ID-based opposites)
- EPackage and EFactory
- Resource and ResourceSet infrastructure
- Binary tree containment tests (BinTree model)
- Company cross-reference tests
- Shared reference tests
- Multi-level containment hierarchy tests
- JSON parser for model instances
- JSON serialiser with sorted keys
- Round-trip tests for all data types
- Comprehensive error handling
- SwiftXML dependency added
- XMI parser foundation (Step 4.1)
- XMI metamodel deserialisation (Step 4.2) - EPackage, EClass, EEnum, EDataType, EAttribute, EReference
- XMI instance deserialisation (Step 4.3) - Dynamic object creation from instance files
- Dynamic attribute parsing with type inference - Arbitrary XML attributes parsed without hardcoding
- XPath reference resolution (Step 4.4) - Same-resource references with XPath-style navigation
- XMI serialiser (Step 4.5) - Full serialisation with attributes, containment, and cross-references
- Round-trip tests - XMI → memory → XMI with in-memory verification at each step
- Cross-resource references (Step 4.6)
- JSON parser for model instances (Step 5.1)
- JSON serialiser with sorted keys (Step 5.2)
- Dynamic EClass creation from JSON - Type inference for attributes and references
- Boolean type handling fix - Boolean detection from Foundation's JSONSerialisation
- Multiple root objects support - Arrays of JSON root objects
- Cross-format conversion - XMI ↔ JSON bidirectional conversion
- Round-trip tests for all data types
- PyEcore compatibility validation - minimal.json and intfloat.json patterns
- Comprehensive error handling
See the details in the LICENCE file.
Swift Modelling aims for 100% round-trip compatibility with:
This implementation is based on the following standards and technologies:
- Eclipse Modeling Framework (EMF) - The reference EMF implementation
- OMG MOF (Meta Object Facility) - The metamodelling standard
- OMG XMI (XML Metadata Interchange) - The XML serialisation format
- OMG OCL (Object Constraint Language) - The constraint and query language