Skip to content

Commit 5d7c1ac

Browse files
committed
Fix the transformer being cleared for Codable properties
This should fix issue #27. The `transformerName` got reset as part of processing the model options.
1 parent e225811 commit 5d7c1ac

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Sources/ManagedModels/SchemaCompatibility/NSAttributeDescription+Data.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ public extension NSAttributeDescription {
165165
if let hashModifier { versionHashModifier = hashModifier }
166166
if let defaultValue { self.defaultValue = defaultValue }
167167
isOptional = valueType is any AnyOptional.Type
168+
169+
assert(valueTransformerName == nil)
170+
valueTransformerName = nil
168171
if valueType != Any.self { self.valueType = valueType }
172+
169173
setOptions(options)
170174
}
171175
}
@@ -177,7 +181,6 @@ private extension NSAttributeDescription {
177181
allowsExternalBinaryDataStorage = false
178182
isIndexedBySpotlight = false
179183
isTransient = false
180-
valueTransformerName = nil
181184
if #available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) {
182185
allowsCloudEncryption = false
183186
}
@@ -193,8 +196,10 @@ private extension NSAttributeDescription {
193196
case .ephemeral: isTransient = true
194197

195198
case .transformableByName(let name):
199+
assert(valueTransformerName == nil)
196200
valueTransformerName = name
197201
case .transformableByType(let type):
202+
assert(valueTransformerName == nil)
198203
valueTransformerName = NSStringFromClass(type)
199204

200205
case .allowsCloudEncryption: // FIXME: restrict availability

Tests/ManagedModelTests/CodablePropertiesTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ final class CodablePropertiesTests: XCTestCase {
2828
defaultValue: nil
2929
)
3030
XCTAssertEqual(attribute.name, "sip")
31+
XCTAssertEqual(attribute.attributeType, .transformableAttributeType)
3132

3233
let transformerName = try XCTUnwrap(
3334
ValueTransformer.valueTransformerNames().first(where: {

0 commit comments

Comments
 (0)