FieldContainer

public enum FieldContainer<O> where O : CoreStoreObject

The containing type for value properties. Use the Field typealias instead for shorter syntax.

class Pet: CoreStoreObject {

    @Field.Stored("species")
    var species = ""

    @Field.Stored("nickname")
    var nickname: String?

    @Field.Coded("color", coder: FieldCoders.Plist.self)
    var eyeColor: UIColor?

    @Field.Relationship("owner", inverse: \.$pets)
    var owner: Person?

    @Field.Relationship("children")
    var children: Array<Pet>

    @Field.Relationship("parents", inverse: \.$children)
    var parents: Set<Pet>
}

Stored

  • The containing type for stored property values. Any type that conforms to FieldStorableType are supported.

    class Person: CoreStoreObject {
    
        @Field.Stored("title")
        var title: String = "Mr."
    
        @Field.Stored("nickname")
        var nickname: String?
    }
    

    Important

    Field properties are required to be used as @propertyWrappers. Any other declaration not using the @Field.Stored(...) var syntax will be ignored.
    See more

    Declaration

    Swift

    @propertyWrapper
    public struct Stored<V> : AttributeKeyPathStringConvertible, FieldAttributeProtocol where V : FieldStorableType

Coded

  • The containing type for stored property values. Any type supported by the specified encoder/decoder are allowed.

    class Animal: CoreStoreObject {
    
        @Field.Coded("eyeColor", coder: FieldCoders.NSCoding.self)
        var eyeColor: UIColor = .black
    
        @Field.Coded(
            "bloodType",
            coder: {
                encode: { $0.toData() },
                decode: { BloodType(fromData: $0) }
            }
        )
        var bloodType: BloodType = .unknown
    }
    

    Important

    Field properties are required to be used as @propertyWrappers. Any other declaration not using the @Field.Stored(...) var syntax will be ignored.
    See more

    Declaration

    Swift

    @propertyWrapper
    public struct Coded<V> : AttributeKeyPathStringConvertible, FieldAttributeProtocol

Relationship

  • The containing type for relationships. Any CoreStoreObject subclass can be a destination type. Inverse relationships should be declared from the destination type as well, using the inverse: argument for the relationship.

    class Dog: CoreStoreObject {
    
        @Field.Relationship("master")
        var master: Person?
    }
    
    class Person: CoreStoreObject {
    
        @Field.Relationship("pets", inverse: \.$master)
        var pets: Set<Dog>
    }
    

    Important

    Field properties are required to be used as @propertyWrappers. Any other declaration not using the @Field.Relationship(...) var syntax will be ignored.
    See more

    Declaration

    Swift

    @propertyWrapper
    public struct Relationship<V> : RelationshipKeyPathStringConvertible, FieldRelationshipProtocol where V : FieldRelationshipType
    extension FieldContainer.Relationship: ToManyRelationshipKeyPathStringConvertible where V: FieldRelationshipToManyType

Virtual

  • The containing type for computed property values. Because this value is not persisted to the backing store, any type is supported. Field.Virtual properties are not allowed to have initial values, including nil for optional types.

    class Animal: CoreStoreObject {
    
        @Field.Virtual(
            "pluralName",
            customGetter: { (object, field) in
                return object.$species.value + "s"
            }
        )
        var pluralName: String
    
        @Field.Stored("species")
        var species: String = ""
    }
    

    Important

    Field properties are required to be used as @propertyWrappers. Any other declaration not using the @Field.Virtual(...) var syntax will be ignored.
    See more

    Declaration

    Swift

    @propertyWrapper
    public struct Virtual<V> : AttributeKeyPathStringConvertible, FieldAttributeProtocol