Documentation/SwiftGenKit Contexts/coredata.md
The core data parser accepts a xcdatamodeld (or xcdatamodel) file. The parser will load all the configurations, entities, and fetch requests for each model.
The output context has the following structure:
models: Array — A list of parsed models, with each:
configurations: Dictionary<String, Array<String>> — Map of configuration names and the corresponding list of
entity namesentities: Dictionary – Map of all the entities in the model, each key being the entity's name, and
corresponding value is a dictionary described below:
name: String - Entity nameattributes: Array - List of attributes (see Entity Attribute)className: String - Class name as specified by the user (usually the same as name)isAbstract: Bool - Whether the entity is an abstract or notfetchedProperties: Array - List of fetched properties (see Entity Fetched Property)relationships: Array - List of relationships (see Entity Relationship)shouldGenerateCode: Bool - Whether the template should generate code or not (Xcode will take care of it)superEntity: String - Name of the super (parent) entityuserInfo: Dictionary - Dictionary of keys/values defined by the useruniquenessConstraints: Array<Array<String>> - List of uniqueness constraints, each being a list of
attributesfetchRequests: Dictionary - All fetch requests, grouped by entity. Each key will be an entity name, each value
will be a list of corresponding fetch requests (see Fetch Request)An Entity Attribute will have the following properties:
name: String - Attribute namecustomClassName: String - Custom class name (if one has been defined)isDerived: Bool - Whether the property is derived or not.isIndexed: Bool - Whether the property is indexed or not.isOptional: Bool - Whether the property is optional or not.isTransient: Bool - Whether the property is transient or not.propertyType: String - Property type, will be "attribute"type: String - Type of the attribute (Transformable, Binary, Boolean, ...)typeName: String - Actual attribute type, based on the values for type, usesScalarValueType and
customClassNameusesScalarValueType: Bool - Whether the property should use scalar value types or not.userInfo: Dictionary - Dictionary of keys/values defined by the userAn Entity Relationship will have the following properties:
name: String - Relationship namedestinationEntity: String - The name of the destination's entity.inverseRelationship: Dictionary - The inverse of this relationship:
name: String: The name of the inverse relationship.entityName: String - The name of the inverse relationship's entity.isIndexed: Bool - Whether the property is indexed or not.isOptional: Bool - Whether the property is optional or not.isOrdered: Bool - Whether the relationship is ordered or unordered.isToMany: Bool - Whether the relationship targets one or more instances.isTransient: Bool - Whether the property is transient or not.propertyType: String - Property type, will be "relationship"userInfo: Dictionary - Dictionary of keys/values defined by the userAn Entity Fetched Property will have the following properties:
name: String - Fetched property namefetchRequest: Dictionary - The fetch request (see Fetch Request)isOptional: Bool - Whether the property is optional or not.propertyType: String - Property type, will be "fetchedProperty"userInfo: Dictionary - Dictionary of keys/values defined by the userA Fetch Request will have the following properties:
name: String - Fetch request nameentity: String - Requested entity namefetchBatchSize: Int - Request batch sizefetchLimit: Int - Request fetch limitincludePropertyValues: Bool - Whether to include property values or notincludesPendingChanges: Bool - Whether to include pending changes or notincludeSubentities: Bool - Whether to include sub-entities or notpredicateString: String - Predicate string for filteringresultType: String - Type of the fetch resultreturnDistinctResults: Bool - Whether to return only the unique results or notreturnsObjectsAsFaults: Bool - Whether to return results as faults or notsubstitutionVariables: Dictionary - Substitution variables (for the predicate), each key being the variable
name, and as value the expected type.models:
- configurations:
Custom:
- "NewEntity"
Default:
- "AbstractEntity"
- "ChildEntity"
- "MainEntity"
- "NewEntity"
- "SecondaryEntity"
entities:
AbstractEntity:
attributes: []
className: "AbstractEntity"
fetchedProperties: []
isAbstract: true
name: "AbstractEntity"
relationships: []
superEntity: ""
uniquenessConstraints: []
userInfo: {}
ChildEntity:
attributes: []
className: "ChildEntity"
fetchedProperties: []
isAbstract: false
name: "ChildEntity"
relationships: []
superEntity: "MainEntity"
uniquenessConstraints: []
userInfo:
key: "value"
MainEntity:
attributes:
- customClassName: "NSAttributedString"
isIndexed: false
isOptional: true
isTransient: false
name: "attributedString"
propertyType: "attribute"
type: "Transformable"
typeName: "NSAttributedString"
userInfo: {}
usesScalarValueType: false
- customClassName: ""
isIndexed: false
isOptional: true
isTransient: false
name: "boolean"
propertyType: "attribute"
type: "Boolean"
typeName: "Bool"
userInfo: {}
usesScalarValueType: true
- customClassName: ""
isIndexed: false
isOptional: true
isTransient: false
name: "float"
propertyType: "attribute"
type: "Float"
typeName: "Float"
userInfo: {}
usesScalarValueType: true
- customClassName: ""
isIndexed: false
isOptional: true
isTransient: false
name: "int64"
propertyType: "attribute"
type: "Integer 64"
typeName: "Int64"
userInfo: {}
usesScalarValueType: true
className: "MainEntity"
fetchedProperties:
- fetchRequest:
entity: "NewEntity"
fetchBatchSize: 0
fetchLimit: 0
includePropertyValues: true
includeSubentities: true
includesPendingChanges: true
name: "fetchedPropertyFetchRequest"
predicateString: "true == true"
resultType: "Object"
returnDistinctResults: false
returnsObjectsAsFaults: true
substitutionVariables: {}
isOptional: true
name: "fetchedProperty"
propertyType: "fetchedProperty"
userInfo:
key: "value"
isAbstract: false
name: "MainEntity"
relationships:
- destinationEntity: "SecondaryEntity"
inverseRelationship:
entityName: "SecondaryEntity"
name: "manyToMany"
isIndexed: false
isOptional: true
isOrdered: false
isToMany: true
isTransient: false
name: "manyToMany"
propertyType: "relationship"
userInfo: {}
superEntity: ""
uniquenessConstraints: []
userInfo:
key: "value"
NewEntity:
attributes:
- customClassName: ""
isIndexed: false
isOptional: true
isTransient: false
name: "identifier"
propertyType: "attribute"
type: "UUID"
typeName: "UUID"
userInfo: {}
usesScalarValueType: false
className: "NewEntity"
fetchedProperties: []
isAbstract: false
name: "NewEntity"
relationships: []
superEntity: "AbstractEntity"
uniquenessConstraints:
- - "identifier"
userInfo: {}
SecondaryEntity:
attributes:
- customClassName: ""
isIndexed: false
isOptional: false
isTransient: false
name: "name"
propertyType: "attribute"
type: "String"
typeName: "String"
userInfo: {}
usesScalarValueType: false
className: "SecondaryEntity"
fetchedProperties: []
isAbstract: false
name: "SecondaryEntity"
relationships:
- destinationEntity: "MainEntity"
inverseRelationship:
entityName: "MainEntity"
name: "manyToMany"
isIndexed: false
isOptional: true
isOrdered: false
isToMany: true
isTransient: false
name: "manyToMany"
propertyType: "relationship"
userInfo: {}
superEntity: ""
uniquenessConstraints: []
userInfo: {}
fetchRequests:
MainEntity:
- entity: "MainEntity"
fetchBatchSize: 0
fetchLimit: 0
includePropertyValues: true
includeSubentities: true
includesPendingChanges: true
name: "ObjectIDFetchRequest"
predicateString: "oneToOne.name == $NAME"
resultType: "Object ID"
returnDistinctResults: false
returnsObjectsAsFaults: true
substitutionVariables:
NAME: "String"