struct - Swift - From Dictionary to NSManagedObject -
i trying value dictionary , set attributes class values
this have done:
class myclass : nsmanagedobject{ @nsmanaged var remoteid:nsnumber @nsmanaged var creationdate:nsdate @nsmanaged var title:string @nsmanaged var total:nsnumber func fromdictionary(dictionary:dictionary<string,anyobject>) { if let x:int = dictionary["id"]! as? int { remoteid = nsnumber(integer: x) } if let x:string = dictionary["creation_date"]! as? string { creationdate = x.formatteddate() } if let x:double = dictionary["total"]! as? double { total = nsnumber(double: x) } if let x:string = dictionary["title"]! as? string { title = x } }
i'm looking way optimize or function in more generic way, in order usable other classes
until attempted use enum (to enumerate dictionary keys, seems me wrong way)
i trying have that
enum keytypes { case int case currency case text case bool case date } struct fields { var keyname:string var keytype:keytypes }
then
var xx = fields[]() xx.append(fields("id",keytypes.int)) xx.append(fields("creationdate",keytypes.int)) ...
and looping array.
do have better idea?
Comments
Post a Comment