CoreStore v7.1.0 Release Notes
Release Date: 2020-03-27 // about 4 years ago-
โก๏ธ Maintenance updates
- ๐ Xcode 11.4 and Swift 5.2 support
๐ New Property Wrappers syntax
โช โ ๏ธ These changes apply only to
CoreStoreObject
subclasses, notNSManagedObject
s.๐ฑ โผ๏ธ Please take note of the warnings below before migrating or else the model's hash might change.
๐ If conversion is too risky, the current
Value.Required
,Value.Optional
,Transformable.Required
,Transformable.Optional
,Relationship.ToOne
,Relationship.ToManyOrdered
, andRelationship.ToManyUnordered
will all be supported for while so you can opt to use them as is for now.๐ฑ โผ๏ธ If you are confident about conversion, I cannot stress this enough, but please make sure to set your schema's
VersionLock
before converting!@Field.Stored
(replacement for non "transient"Value.Required
andValue.Optional
)class Person: CoreStoreObject { @Field.Stored("title") var title: String = "Mr."@Field.Stored("nickname") var nickname: String?}
๐ฑ โ ๏ธ Only
Value.Required
andValue.Optional
that are NOT transient values can be converted toField.Stored
.
๐ฑ โ ๏ธ When converting, make sure that all parameters, including the default values, are exactly the same or else the model's hash might change.@Field.Virtual
(replacement for "transient" versions ofValue.Required
andValue.Optional
)class Animal: CoreStoreObject { @Field.Virtual( "pluralName", customGetter: { (object, field) inreturn object.$species.value + "s" } ) var pluralName: [email protected]("species") var species: String = ""}
๐ฑ โ ๏ธ Only
Value.Required
andValue.Optional
that ARE transient values can be converted toField.Virtual
.
๐ฑ โ ๏ธ When converting, make sure that all parameters, including the default values, are exactly the same or else the model's hash might change.๐
@Field.Coded
(replacement forTransformable.Required
andTransformable.Optional
, with additional support for custom encoders such as JSON)class Person: CoreStoreObject { @Field.Coded( "bloodType", coder: { encode: { $0.toData() }, decode: { BloodType(fromData: $0) } } ) var bloodType: BloodType?}
๐ฑ โผ๏ธ The current
Transformable.Required
andTransformable.Optional
mechanism have no safe conversion to@Field.Coded
. Please use@Field.Coded
only for newly added attributes.@Field.Relationship
(replacement forRelationship.ToOne
,Relationship.ToManyOrdered
, andRelationship.ToManyUnordered
)class Pet: CoreStoreObject { @Field.Relationship("master") var master: Person?}class Person: CoreStoreObject { @Field.Relationship("pets", inverse: \.$master) var pets: Set\<Pet\>}
๐ฑ โ ๏ธ
Relationship.ToOne<T>
maps toT?
,Relationship.ToManyOrdered
maps toArray<T>
, andRelationship.ToManyUnordered
maps toSet<T>
๐ฑ โ ๏ธ When converting, make sure that all parameters, including the default values, are exactly the same or else the model's hash might change.Usage
Before diving into the properties themselves, note that they will effectively force you to use a different syntax for queries:
- Before:
From<Person>.where(\.title == "Mr.")
- After:
From<Person>.where(\.$title == "Mr.")
There are a several advantages to using these Property Wrappers:
- ๐ The
@propertyWrapper
versions will be magnitudes performant and efficient than their current implementations. CurrentlyMirror
reflection is used a lot to inject theNSManagedObject
reference into the properties. With@propertyWrapper
s this will be synthesized by the compiler for us. (See apple/swift#25884) - The
@propertyWrapper
versions, beingstruct
s, will give the compiler a lot more room for optimizations which were not possible before due to the need for mutable classes. - You can now add computed properties that are accessible to both
ObjectSnapshot
s andObjectPublisher
s by declaring them as@Field.Virtual
. Note that forObjectSnapshot
s, the computed values are evaluated only once during creation and are not recomputed afterwards.
The only disadvantage will be:
- โก๏ธ You need to update your code by hand to migrate to the new
@propertyWrapper
s
(But the legacy ones will remain available for quite a while, so while it is recommended to migrate soon, no need to panic)