Entity

public final class Entity<O> : DynamicEntity where O : CoreStoreObject
extension Entity: CustomDebugStringConvertible, CoreStoreDebugStringConvertible

The Entity<O> contains NSEntityDescription metadata for CoreStoreObject subclasses. Pass the Entity instances to CoreStoreSchema initializer.

class Animal: CoreStoreObject {
    let species = Value.Required<String>("species", initial: "")
    let nickname = Value.Optional<String>("nickname")
    let master = Relationship.ToOne<Person>("master")
}

class Person: CoreStoreObject {
    let name = Value.Required<String>("name", initial: "")
    let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
}

CoreStoreDefaults.dataStack = DataStack(
    CoreStoreSchema(
        modelVersion: "V1",
        entities: [
            Entity<Animal>("Animal"),
            Entity<Person>("Person")
        ]
    )
)

See also

CoreStoreSchema

See also

CoreStoreObject
  • Initializes an Entity. Always provide a concrete generic type to Entity.

    Entity<Animal>("Animal")
    

    Declaration

    Swift

    public convenience init(_ entityName: String, isAbstract: Bool = false, versionHashModifier: String? = nil, indexes: [[PartialKeyPath<O>]] = [], uniqueConstraints: [[PartialKeyPath<O>]])

    Parameters

    entityName

    the NSEntityDescription name to use for the entity

    isAbstract

    set to true if the entity is meant to be an abstract class and can only be initialized with subclass types.

    versionHashModifier

    the version hash modifier for the entity. Used to mark or denote an entity as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where, for example, the structure of an entity is unchanged but the format or content of data has changed.)

    indexes

    the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain KeyPaths to properties of the entity.

    uniqueConstraints

    sets uniqueness constraints for the entity. A uniqueness constraint is a set of one or more KeyPaths whose value must be unique over the set of instances of that entity. This value forms part of the entity’s version hash. Uniqueness constraint violations can be computationally expensive to handle. It is highly suggested that there be only one uniqueness constraint per entity hierarchy. Uniqueness constraints must be defined at the highest level possible, and CoreStore will raise an assertion failure if unique constraints are added to a sub entity.

  • Initializes an Entity. Always provide a concrete generic type to Entity.

    Entity<Animal>("Animal")
    

    Declaration

    Swift

    public convenience init(_ entityName: String, isAbstract: Bool = false, versionHashModifier: String? = nil, indexes: [[PartialKeyPath<O>]] = [])

    Parameters

    entityName

    the NSEntityDescription name to use for the entity

    isAbstract

    set to true if the entity is meant to be an abstract class and can only be initialized with subclass types.

    versionHashModifier

    the version hash modifier for the entity. Used to mark or denote an entity as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where, for example, the structure of an entity is unchanged but the format or content of data has changed.)

    indexes

    the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain KeyPaths to properties of the entity.

  • Initializes an Entity.

    Entity(Animal.self, "Animal")
    

    Declaration

    Swift

    public init(_ type: O.Type, _ entityName: String, isAbstract: Bool = false, versionHashModifier: String? = nil, indexes: [[PartialKeyPath<O>]] = [], uniqueConstraints: [[PartialKeyPath<O>]])

    Parameters

    type

    the DynamicObject type associated with the entity

    entityName

    the NSEntityDescription name to use for the entity

    isAbstract

    set to true if the entity is meant to be an abstract class and can only be initialized with subclass types.

    versionHashModifier

    the version hash modifier for the entity. Used to mark or denote an entity as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where, for example, the structure of an entity is unchanged but the format or content of data has changed.)

    indexes

    the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain KeyPath’s to properties of the entity.

    uniqueConstraints

    sets uniqueness constraints for the entity. A uniqueness constraint is a set of one or more KeyPaths whose value must be unique over the set of instances of that entity. This value forms part of the entity’s version hash. Uniqueness constraint violations can be computationally expensive to handle. It is highly suggested that there be only one uniqueness constraint per entity hierarchy. Uniqueness constraints must be defined at the highest level possible, and CoreStore will raise an assertion failure if unique constraints are added to a sub entity.

  • Initializes an Entity.

    Entity(Animal.self, "Animal")
    

    Declaration

    Swift

    public init(_ type: O.Type, _ entityName: String, isAbstract: Bool = false, versionHashModifier: String? = nil, indexes: [[PartialKeyPath<O>]] = [])

    Parameters

    type

    the DynamicObject type associated with the entity

    entityName

    the NSEntityDescription name to use for the entity

    isAbstract

    set to true if the entity is meant to be an abstract class and can only be initialized with subclass types.

    versionHashModifier

    the version hash modifier for the entity. Used to mark or denote an entity as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where, for example, the structure of an entity is unchanged but the format or content of data has changed.)

    indexes

    the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain KeyPath’s to properties of the entity.

    uniqueConstraints

    sets uniqueness constraints for the entity. A uniqueness constraint is a set of one or more KeyPaths whose value must be unique over the set of instances of that entity. This value forms part of the entity’s version hash. Uniqueness constraint violations can be computationally expensive to handle. It is highly suggested that there be only one uniqueness constraint per entity hierarchy. Uniqueness constraints must be defined at the highest level possible, and CoreStore will raise an assertion failure if unique constraints are added to a sub entity.

CustomDebugStringConvertible

  • Declaration

    Swift

    public var debugDescription: String { get }