I would like to use Core Data for a drawing application where the user draws in a UIImageView using CGPoints has the option to save and at a later time load different drawings (and add to them if the user desires - e.g. mutability)
I've read through some cored data tutorials and skimmed the Core Data Programming guide but I can't seem to figure out what need to be done to save the drawing to Core Data i.e. what type of attribute to use (transformable I suppose) and how exactly to get the CGPoints (again transform I suppose) to work with the managedObject I'll need to create.
To draw I'm using methods:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {...}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {...}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {...}
In the iPhoneCoreDataRecipes project Apple changes the images to data for Core Data - (so you don't have to download the project their code in the implementation file for transforming is at the bottom of the post). In this case it's converting PNGs to data so I'm not sure how to apply this to CGPoints in a UIImageView. I'm happy to supply more of my code if necessary.
Thanks in advance,
James
.
.
Apple's Recipe code:
@implementation Recipe
@dynamic name, image, overview, thumbnailImage, instructions, ingredients, type, prepTime;
@end
@implementation ImageToDataTransformer
+ (BOOL)allowsReverseTransformation {
return YES;
}
+ (Class)transformedValueClass {
return [NSData class];
}
- (id)transformedValue:(id)value {
NSData *data = UIImagePNGRepresentation(value);
return data;
}
- (id)reverseTransformedValue:(id)value {
UIImage *uiImage = [[UIImage alloc] initWithData:value];
return [uiImage autorelease];
}
@end