First, add your property to the data model as usual, and make it a 'transformable' property (in my case the property is called actionRules) :
Then add the normal attribute to your coredata managed object header file (and here you can actually refer to it as an array) :
And add the @dynamic to the main file :
Then some slightly more weird stuff. You add an entirely separate @interface to the same header file, using the name of the new property, and setting it to NSValueTransformer (you literally put this after the @end of the normal interface) :
Finally, add this entirely new @implementation in the main file. Before or after the other normal implementation is fine (obviously you need to change the 'ActionRules' for the name of your array) :
And thats it - you have an NSArray that you can use throughout your application as usual. Obviously its not mutable, so to add properties, create a mutableCopy of it, change it as required, then set the property as this mutableArray. Still, its quite handy I find, and theres the additional bonus of quickly organised indexing.





No comments:
Post a Comment