Skip to content

Commit

Permalink
Fix the transformer being cleared for Codable properties
Browse files Browse the repository at this point in the history
This should fix issue #27.

The `transformerName` got reset as part of processing
the model options.
  • Loading branch information
helje5 committed Feb 9, 2024
1 parent e225811 commit 5d7c1ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ public extension NSAttributeDescription {
if let hashModifier { versionHashModifier = hashModifier }
if let defaultValue { self.defaultValue = defaultValue }
isOptional = valueType is any AnyOptional.Type

assert(valueTransformerName == nil)
valueTransformerName = nil
if valueType != Any.self { self.valueType = valueType }

setOptions(options)
}
}
Expand All @@ -177,7 +181,6 @@ private extension NSAttributeDescription {
allowsExternalBinaryDataStorage = false
isIndexedBySpotlight = false
isTransient = false
valueTransformerName = nil
if #available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) {
allowsCloudEncryption = false
}
Expand All @@ -193,8 +196,10 @@ private extension NSAttributeDescription {
case .ephemeral: isTransient = true

case .transformableByName(let name):
assert(valueTransformerName == nil)
valueTransformerName = name
case .transformableByType(let type):
assert(valueTransformerName == nil)
valueTransformerName = NSStringFromClass(type)

case .allowsCloudEncryption: // FIXME: restrict availability
Expand Down
1 change: 1 addition & 0 deletions Tests/ManagedModelTests/CodablePropertiesTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class CodablePropertiesTests: XCTestCase {
defaultValue: nil
)
XCTAssertEqual(attribute.name, "sip")
XCTAssertEqual(attribute.attributeType, .transformableAttributeType)

let transformerName = try XCTUnwrap(
ValueTransformer.valueTransformerNames().first(where: {
Expand Down

0 comments on commit 5d7c1ac

Please sign in to comment.