I know this sounds weird, but I would like to store and retrieve small snippets of Objective-C code from a plist. The scenario is this:
I have a plist that stores Core Image filter presets. This is all groovy for everything with numeric values (most of the presets). However, a few of the presets require something like “inputColor” which is a CIColor object (i.e. [CIColor colorWithRed:0.75 green:0.75 blue:0.75]). Is there any way to store something like that in a plist (either as a NSString or maybe NSData) and then retrieve it as usable code?
I realize a logical alternative would be to store the RGB value individually, but the former option would just be a bit more convenient as there are other macro values.
Do you want the plist file to be editable by humans?
If not, notice that
CIColorconforms to theNSCodingprotocol. So you can convert it to anNSDatausingNSKeyedArchiverand store theNSDatain the plist. When you read the plist, you can convert theNSDataback to aCIColorusingNSKeyedUnarchiver.In fact,
CIFilteralso conforms toNSCoding. Perhaps you can just archive and unarchive your filter object. It will automatically archive and unarchive its attributes.