I am searching how to get not managed property names and types of a NSManagedObject subclass.
here is few sample code to help me to ask my question :
@objc(Operation)
public class Operation : NSManagedObject {
@NSManaged var name: String
@NSManaged var amount: NSNumber
}
@objc(Account)
public class Account: NSManagedObject {
@NSManaged var bic: String
@NSManaged var number: String
@NSManaged var operations: Set<Operation>
@NSManaged var servicesSubscriptions: Set<ServiceSubcription>
// and more.
}
extension Account
{
public var lastOperation : Operation {
get
{
return self.operations.last
}
set(value)
{
self.operations.insert(value)
}
}
}
I have found many ways to get property names using reflect() function. reflect() do not work with NSManagedObject at all. (like this simple one)
edit I have found examples with class_copyPropertyList function, that retrieve correctly property names, but don't found yet how to get types. Thank to Tom Harrington comment. (see that sample)
I have found many ways to get Attributes (or relations) of managed objects using NSEntityDescription. (like this one). Which work and get back bic
and number
, but not lastOperation
.
edited updated code sample to match better to reality
So my question is :
How to get back my lastOperation
property, and its type, dynamically at run time ?
edit, what i am trying to do I am parsing json, dnamically using reflection. I need the type (or type name) of a property knowing only its name (i have "lastOperation", and need to get back Operation, or "Operation"). Once i get the type i can instanciate an object, then populate its own properties, using same mechanism (recursively).
Thank you for any help