mardi 22 décembre 2015

Swift: Reflecting properties of subclass of NSManagedObject

When accessing the inner structure of a subclass of NSManagedObject using a Mirror, all managed variables are ignored.

public class Foo: NSManagedObject {
   @NSManaged var bar: String?
}

var f: Foo = ...
// ... creating a Foo in a valid context ...

let mirror = Mirror(reflecting: f)
for c in mirror.children {        // children count == 0
  print("\(c.label!):\(c.value)") // never executed
}

How can reflection mechanisms used on NSManagedObjects.





Aucun commentaire:

Enregistrer un commentaire