-
Notifications
You must be signed in to change notification settings - Fork 395
Template Variables
Generally-speaking, the variables available in a template are the methods on NSEntityDescription
plus a handful added via categories in mogenerator.m
. Additional template variables can be set via the command line option --template-var
.
The most current list will always be the method names in mogenerator.h
for the various class names. Again, the root variable context is the current NSEntityDescription
object.
The following are set when the --v2
option is used to generate modern Obj-C output. You can also turn each feature on separately if you desire.
Name | Type | Description |
---|---|---|
TemplateVar.arc | bool | Use ARC. |
TemplateVar.literals | bool | Use Obj-C literals. |
TemplateVar.modules | bool | Use Obj-C module imports. |
For the current list of all methods, see Apple's Core Data documentation for the class. Commonly-used and useful values are presented below for convenience.
Name | Type | Description |
---|---|---|
managedObjectClassName | String | The name of the class. You'll use this a lot. |
name | String | The name of the entity. |
abstract | bool | True if this is an abstract entity. |
The following are additions to NSEntityDescription
and are available for use as first-class values in your templates.
Name | Type | Description |
---|---|---|
hasCustomSuperentity | bool | True if the entity or its superentity has a custom base class. |
hasSuperentity | bool | True if the entity has a superentity defined in the model file. |
customSuperentity | String | The name of this entity's class, the superentity's class, or NSManagedObject . |
hasCustomBaseCaseImport | bool | True if the user has specified a custom base class import string. |
baseClassImport | String | The user-specified base class import string. |
Name | Type | Description |
---|---|---|
hasAdditionalHeaderFile | bool | True if the user has specified an additional header file to import for this entity (user info key additionalHeaderFileName ). |
additionalHeaderFileName | String | The name of the additional header file to import. |
Name | Type | Description |
---|---|---|
noninheritedAttributes | Array[NSAttributeDescription] | All non-inherited attributes (sorted by name ). |
noninheritedAttributesSansType | Array[NSAttributeDescription] | All non-inherited attributes (except any called type ; see #74). |
noninheritedRelationships | Array[NSRelationshipDescription] | All non-inherited relationships (sorted by name ). |
noninheritedFetchedProperties | Array[NSFetchedPropertyDescription] | All non-inherited fetched properties (sorted by name ). |
indexedNoninheritedAttributes | Array[NSAttributeDescription] | All non-inherited attributes whose isIndexed is YES. |
fetchedPropertiesByName | Dictionary{String, NSFetchedPropertyDescription} | All fetched properties. |
Note about user info keys: Only keys whose name consists of Unicode alphanumerics and/or the underscore will be returned. The hasUserInfoKeys
respects this limitation and will be zero if no keys match.
Name | Type | Description |
---|---|---|
hasUserInfoKeys | bool | True if the entity has userInfo keys. |
userInfoByKeys | Dictionary{String, String} | All userInfo keys (see note above). |
userInfoKeyValues | Array[NSEntityUserInfoDescription] | All of the user info keys, sorted by name (see note above). |
When iterating over a collection of attributes, the following additional variables are available on the attribute.
Name | Type | Description |
---|---|---|
hasScalarAttributeType | bool | True if the attribute is numeric (including boolean). |
scalarAttributeType | String | The language-aware scalar (native) type (eg. uint32_t or UInt32 ). |
scalarAccessorMethodName | String | The method name on NSNumber that will return the scalar type. |
scalarFactoryMethodName | String | The class method on NSNumber that will create a number from the scalar type. |
hasDefinedAttributeType | bool | True if the attribute has a defined type in the model (ie. is not set to "undefined"). |
hasAttributeTransformableProtocols | bool | True if the user info key attributeTransformableProtocols is set. |
objectAttributeTransformableProtocols | Array[String] | The list of user-specified protocols this property uses (to be declared at the start of the machine header file). |
objectAttributeClassName | String | The class of the attribute. |
objectAttributeType | String | The language-aware type declaration statement. |
hasTransformableAttributeType | bool | True if the attribute is set to Transformable in the model. |
isReadonly | bool | True if the attribute has been declared read-only (via user info key mogenerator.readonly ). |
Name | Type | Description |
---|---|---|
jr_isOrdered | bool | Returns the -[NSRelationshipDescription isOrdered] value, but only if the object responds to it (for earlier versions of Core Data). |
immutableCollectionClassName | String | The language- and ordered-aware name of the immutable relationship collection class. |
mutableCollectionClassName | String | The language- and ordered-aware name of the mutable relationship collection class. |