I'm writing to CoreData with key-values:
entity.setValue(value: <Any?>, forKey: <String>)
Before writing to CoreData I store the value and the field name in vars:
var value: Any?
var field: String
I would like to do a simple validation before I attempt to write to CoreData. The function validateValue(_:forKey:) seems to satisfy my needs but I don't understand how to use it:
try entity.validateValue(_ value: AutoreleasingUnsafeMutablePointer<AnyObject?>, forKey: String)
In my case it would be like:
do {
try entity.validateValue(value, forKey: field)
} catch {
let validationError = error as NSError
print(validationError)
}
But how do I pass
var value: Any
to
AutoreleasingUnsafeMutablePointer<AnyObject?>
Is it even possible to use the validateValue function in this context?
Thanks!