title: How to call the validateValue method
body: <p>I'm trying to make a generic NSCoding implementation and have a problem with decoding when the type of the object has changed in the mean time because of a newer version of the app.</p>
  
  <p>I have a problem with calling the validateValue method from Swift. The function signature is:</p>
  
  <pre><code>func validateValue(_ ioValue: AutoreleasingUnsafeMutablePointer&lt;AnyObject?&gt;, forKey key: String, error outError: NSErrorPointer) -&gt; Bool
  </code></pre>
  
  <p>As a reference, the Apple documentation can be found here: <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueCoding_Protocol/index.html#//apple_ref/occ/instm/NSObject/validateValue:forKey:error:" rel="noreferrer">NSCoding validateValue</a></p>
  
  <p>The code that I want to create is:</p>
  
  <pre><code>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: &amp;error)
                  if y {
                      theObject.setValue(newValue, forKey: key)
                  }
              }
          }
      }
  </code></pre>
  
  <p>I can't get the call to .validateValue correct. I keep getting compile errors. How should I call it.
  The toDictionary function can be found at: <a href="https://github.com/evermeer/EVReflection" rel="noreferrer">EVReflection</a></p>
  
  <p><strong>Update</strong>: I just found out that this code does compile:</p>
  
  <pre><code>        var ioValue: AutoreleasingUnsafeMutablePointer&lt;AnyObject?&gt; = nil
          var y:Bool = theObject.validateValue(ioValue, forKey: key, error: nil)
  </code></pre>
  
  <p>This would mean that the value which is of type AnyObject? could not be casted to AutoreleasingUnsafeMutablePointer</p>