From a971db337e7e19509e64eff40e5b5e4a2c751e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Sat, 7 Oct 2023 14:21:18 +0200 Subject: [PATCH] Do not set the `attributeValueClassName` Gives issues w/ optional base types when nil is set (converted to `NSNull` which then doesn't match an internal preconditions). --- .../CoreDataPrimitiveValue.swift | 30 +++++++++---------- .../NSAttributeDescription+Data.swift | 8 +++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Sources/ManagedModels/SchemaCompatibility/CoreDataPrimitiveValue.swift b/Sources/ManagedModels/SchemaCompatibility/CoreDataPrimitiveValue.swift index d79f16e..1228903 100644 --- a/Sources/ManagedModels/SchemaCompatibility/CoreDataPrimitiveValue.swift +++ b/Sources/ManagedModels/SchemaCompatibility/CoreDataPrimitiveValue.swift @@ -9,7 +9,7 @@ public extension CoreData.NSAttributeDescription { struct TypeConfiguration { let attributeType : NSAttributeType let isOptional : Bool - let attributeValueClassName : String + let attributeValueClassName : String? } } @@ -37,35 +37,35 @@ extension Int: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .integer64AttributeType, isOptional : false, - attributeValueClassName : "NSNumber" + attributeValueClassName : nil ) } extension Int16: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .integer16AttributeType, isOptional : false, - attributeValueClassName : "NSNumber" + attributeValueClassName : nil ) } extension Int32: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .integer32AttributeType, isOptional : false, - attributeValueClassName : "NSNumber" + attributeValueClassName : nil ) } extension Int64: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .integer64AttributeType, isOptional : false, - attributeValueClassName : "NSNumber" + attributeValueClassName : nil ) } extension Int8: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .integer16AttributeType, isOptional : false, - attributeValueClassName : "NSNumber" + attributeValueClassName : nil ) } @@ -91,7 +91,7 @@ extension String: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .stringAttributeType, isOptional : false, - attributeValueClassName : "NSString" + attributeValueClassName : nil ) } @@ -99,7 +99,7 @@ extension Bool: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .booleanAttributeType, isOptional : false, - attributeValueClassName : "NSNumber" + attributeValueClassName : nil ) } @@ -107,14 +107,14 @@ extension Double: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .doubleAttributeType, isOptional : false, - attributeValueClassName : "NSNumber" + attributeValueClassName : nil ) } extension Float: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .floatAttributeType, isOptional : false, - attributeValueClassName : "NSNumber" + attributeValueClassName : nil ) } @@ -124,7 +124,7 @@ extension Date: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .dateAttributeType, isOptional : false, - attributeValueClassName : "NSDate" + attributeValueClassName : nil ) } @@ -132,7 +132,7 @@ extension Data: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .binaryDataAttributeType, isOptional : false, - attributeValueClassName : "NSDate" + attributeValueClassName : nil ) } @@ -140,7 +140,7 @@ extension Decimal: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .decimalAttributeType, isOptional : false, - attributeValueClassName : "NSDecimalNumber" + attributeValueClassName : nil ) } @@ -148,7 +148,7 @@ extension UUID: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .UUIDAttributeType, isOptional : false, - attributeValueClassName : "NSUUID" + attributeValueClassName : nil ) } @@ -156,6 +156,6 @@ extension URL: CoreDataPrimitiveValue { public static let coreDataValue = NSAttributeDescription.TypeConfiguration( attributeType : .URIAttributeType, isOptional : false, - attributeValueClassName : "NSURL" + attributeValueClassName : nil ) } diff --git a/Sources/ManagedModels/SchemaCompatibility/NSAttributeDescription+Data.swift b/Sources/ManagedModels/SchemaCompatibility/NSAttributeDescription+Data.swift index 4aec422..141ad3a 100644 --- a/Sources/ManagedModels/SchemaCompatibility/NSAttributeDescription+Data.swift +++ b/Sources/ManagedModels/SchemaCompatibility/NSAttributeDescription+Data.swift @@ -42,7 +42,9 @@ extension CoreData.NSAttributeDescription: SchemaProperty { let config = primitiveType.coreDataValue self.attributeType = config.attributeType self.isOptional = config.isOptional - self.attributeValueClassName = config.attributeValueClassName + if let newClassName = config.attributeValueClassName { + self.attributeValueClassName = newClassName + } return } @@ -55,7 +57,9 @@ extension CoreData.NSAttributeDescription: SchemaProperty { let config = primitiveType.coreDataValue self.attributeType = config.attributeType self.isOptional = config.isOptional - self.attributeValueClassName = config.attributeValueClassName + if let newClassName = config.attributeValueClassName { + self.attributeValueClassName = newClassName + } return true } else {