Skip to content

Commit

Permalink
Do not set the attributeValueClassName
Browse files Browse the repository at this point in the history
Gives issues w/ optional base types when nil is
set (converted to `NSNull` which then doesn't
match an internal preconditions).
  • Loading branch information
helje5 committed Oct 7, 2023
1 parent 7bab02e commit a971db3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public extension CoreData.NSAttributeDescription {
struct TypeConfiguration {
let attributeType : NSAttributeType
let isOptional : Bool
let attributeValueClassName : String
let attributeValueClassName : String?
}
}

Expand Down Expand Up @@ -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
)
}

Expand All @@ -91,30 +91,30 @@ extension String: CoreDataPrimitiveValue {
public static let coreDataValue = NSAttributeDescription.TypeConfiguration(
attributeType : .stringAttributeType,
isOptional : false,
attributeValueClassName : "NSString"
attributeValueClassName : nil
)
}

extension Bool: CoreDataPrimitiveValue {
public static let coreDataValue = NSAttributeDescription.TypeConfiguration(
attributeType : .booleanAttributeType,
isOptional : false,
attributeValueClassName : "NSNumber"
attributeValueClassName : nil
)
}

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
)
}

Expand All @@ -124,38 +124,38 @@ extension Date: CoreDataPrimitiveValue {
public static let coreDataValue = NSAttributeDescription.TypeConfiguration(
attributeType : .dateAttributeType,
isOptional : false,
attributeValueClassName : "NSDate"
attributeValueClassName : nil
)
}

extension Data: CoreDataPrimitiveValue {
public static let coreDataValue = NSAttributeDescription.TypeConfiguration(
attributeType : .binaryDataAttributeType,
isOptional : false,
attributeValueClassName : "NSDate"
attributeValueClassName : nil
)
}

extension Decimal: CoreDataPrimitiveValue {
public static let coreDataValue = NSAttributeDescription.TypeConfiguration(
attributeType : .decimalAttributeType,
isOptional : false,
attributeValueClassName : "NSDecimalNumber"
attributeValueClassName : nil
)
}

extension UUID: CoreDataPrimitiveValue {
public static let coreDataValue = NSAttributeDescription.TypeConfiguration(
attributeType : .UUIDAttributeType,
isOptional : false,
attributeValueClassName : "NSUUID"
attributeValueClassName : nil
)
}

extension URL: CoreDataPrimitiveValue {
public static let coreDataValue = NSAttributeDescription.TypeConfiguration(
attributeType : .URIAttributeType,
isOptional : false,
attributeValueClassName : "NSURL"
attributeValueClassName : nil
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down

0 comments on commit a971db3

Please sign in to comment.