swift2 - core data: save different types as the same attribute -


i have core data entity has attribute can represent different types of values (int, double, date, string).

would lead problems (e.g. loss of precision) somewhere down line if convert these values string , back?

@nsmanaged var storedtype : int @nsmanaged var storedvalue : string var value: any? { {  set {   switch newvalue   {   case int:     self.storedvalue = string(newvalue)     self.storedtype = 0    ...    case string     self.storedvalue = newvalue     self.storedtype = 5   }  }  {   switch newvalue   {   case 0:     return int(self.storedvalue)    ...    case 5:     return self.storedvalue   }  } } } 

while think long , hard architecture first agree there may case functionality , else should question asked*.

one option use transformable property type. type allows coredata store object nscoding compliant (nsarray, nsdictionary etc.) , nsstring , nsnumber believe.

thus can retrieve object generic type (id in objective-c, don't know equivalent in swift) , query type , cast whatever need.

the downside of approach of course loose lot of coredata power in querying store values store transformable attributes become more or less opaque predicates , such. works fine walking core data structure key paths.

*) believe read equivalent variant data type in vb 1 of joel spolsky's contributions language...


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -