I am trying to create a general implementation of NSCoding and have a problem with decoding when the type of the object has changed on average due to a newer version of the application.
I have a problem calling the validateValue method from Swift. Function Signature:
func validateValue(_ ioValue: AutoreleasingUnsafeMutablePointer<AnyObject?>, forKey key: String, error outError: NSErrorPointer) -> Bool
For reference, Apple's documentation can be found here: NSCoding validateValue
The code I want to create is:
public class func decodeObjectWithCoder(theObject:NSObject, aDecoder: NSCoder) { for (key, value) in toDictionary(theObject) { if aDecoder.containsValueForKey(key) { let newValue: AnyObject? = aDecoder.decodeObjectForKey(key) NSLog("set key \(key) with value \(newValue)") var error:NSError? var y:Bool = theObject.validateValue(newValue, forKey: key, error: &error) if y { theObject.setValue(newValue, forKey: key) } } } }
I cannot correctly call .validateValue. I keep getting compilation errors. What should I call it? The toDictionary function can be found at: EVReflection
Update : I just found out that this code compiles:
var ioValue: AutoreleasingUnsafeMutablePointer<AnyObject?> = nil var y:Bool = theObject.validateValue(ioValue, forKey: key, error: nil)
Does this mean a value that is of type AnyObject? cannot be sent to AutoreleasingUnsafeMutablePointer
source share