Structure
EFactory
A factory for creating instances of model elements.
struct EFactory
Overview
EFactory provides the factory pattern for creating instances of classes defined in a metamodel package. Each factory is associated with a specific EPackage and can create instances of the classes in that package.
Key Capabilities
-
Create Objects: Instantiate objects of a given class using create(_:)
-
Parse Data Types: Convert string literals to typed values using createFromString(_:_:)
-
Convert to Strings: Convert typed values to string literals using convertToString(_:_:)
Example
let companyPackage = EPackage(
name: "company",
nsURI: "http://example.org/company",
nsPrefix: "company"
)
let factory = EFactory(ePackage: companyPackage)
// Create an Employee instance (in practice, would return a proper object)
if let employeeClass = companyPackage.getEClass("Employee") {
let employee = factory.create(employeeClass)
print("Created instance of \(employee.eClass.name)")
}
// Parse a string into an Int
let intType = EDataType(name: "EInt")
if let value = factory.createFromString(intType, "42") as? Int {
print("Parsed value: \(value)")
}
Important Note
This basic implementation creates generic EObject instances. In a complete implementation, factories would be code-generated or use dynamic proxies to create specific typed instances with proper feature storage.
Topics
Operators
Compares two factories for equality.
Initializers
Creates a new factory.
Instance Properties
Annotations attached to this factory.
The metaclass describing this factory.
The package that this factory creates instances for.
Unique identifier for this factory.
The name of this factory.
Instance Methods
Converts a value to a string literal for the given data type.
Creates an instance of the specified class.
Creates a value from a string literal for the given data type.
Reflectively retrieves the value of a feature.
Checks whether a feature has been explicitly set.
Reflectively sets the value of a feature.
Unsets a feature, returning it to its default value.
Hashes the essential components of this factory.
Type Aliases
The type of classifier for this factory.
Default Implementations
Relationships
Conforms To
See Also
Supporting Types
Base protocol for model elements that can have annotations.
Base protocol for model elements that have a name.