Closed
Description
I'm sometimes getting this:
Unacceptable type of value for attribute: property = "xyz"; desired type = NSString; given type = NSNull; value = .
In this:
func setValue<T>(forKey key: String, to value: T)
where T: Codable & CoreDataPrimitiveValue & AnyOptional
{
willChangeValue(forKey: key); defer { didChangeValue(forKey: key) }
let attr = Self.entity().attributesByName[key]
print("Attr:", attr?.name, attr?.isOptional, attr?.attributeValueClassName)
setPrimitiveValue(value, forKey: key)
}
The property is optional, the valueClassName is set to NSString
. Not quite sure what is going on here.
In CoreData those work:
let item = Item(entity: Item.entity(), insertInto: nil)
assert(item.entity === entity)
item.value = nil
item.setPrimitiveValue(nil, forKey: "value")
but this fails as well:
item.setPrimitiveValue(NSNull(), forKey: "value")
Maybe a bridging issue w/ nil
? As far as I can see, nil
is properly used.
It fails in coerceValueForKey.