Wednesday 15 April 2015

ios - Best way to save and retrieve UIColors to Core Data -


I can think of some methods, for example by saving each color component as float, pattern image Saving the color can be a bit more complex, but I think you can save the name of the image as a string and insert it into the creation code.

Am I on the right track, otherwise what is the best and most efficient way to do this task normally?

You can change your UIColor to NSData And then store it:

  NSData * theData = [NSKeyedArchiver archived data object [UIColor blackcolor]];   

Then you can convert it to your UIColor object:

  UIColor * thecolor = (UIColor *) [NSKeyedUnarchiver UnarchiveObjectWithData: statistics];   

UPD .:

To answer your question in the comments about archiving data, the easiest way is to NSUserDefaults :

  NSData * theData = [NSKEDErchiver stored datahop object: [UIColor blackcolor]]; [[NSUserDefaults Standard Standard Default] Set Object: The Data Fork: @ "Michael"];   

and then retracting it:

  NSData * theData = [[NSUserDefaults standard user default] objectfore: @ "Michael"]; UIColor * theColor = (UIColor *) [NSKEEDAmericcier Unavoidable Objective Data: Dadet];    

No comments:

Post a Comment