In my App i use a Core Data model with only one Entity and some Attributes in it. What I want to achieve:
Attribute A "imagePath" is of type NSString that stores the path to the Document Directory where the corresponding .png image is.
Attribute B "imageCoreData" is of type Binary Data.
I want to move all the images in Document Directory to Core Data.
So I need code that does the following - get the image from Attribute A in Document Directory, convert it to NSData and save it as Binary Data to Attribute B "imageCoreData". And does this for every object i got.
Also it would be great if I could get informed if it´s successfully completed. Maybe also it should work in background to not block the UI.
The same I want for:
Attribute C "date" of type NSDate that stores a date.
Attribute D "dateString" of type NSString.
Get the date from Attribute C and convert the date from NSDate to NSString and save it in Attribute D. I need this also for all objects I got.
UPDATE
I can get a dictionary with all my paths to Document Directory. But how to pull out all images, covert and save to Attribute B ?
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Entity"];
NSEntityDescription *entityImg = [NSEntityDescription entityForName:@"Entity" inManagedObjectContext:self.managedObjectContext];
fetchRequest.resultType = NSDictionaryResultType;
fetchRequest.propertiesToFetch = [NSArray arrayWithObject:[[entityImg propertiesByName] objectForKey:@"imagePath"]];
fetchRequest.returnsDistinctResults = YES;
NSArray *dictionary = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil];
NSLog(@"%@", dictionary);
NSArray *dictionary
. Something strange with that line? - Amin Negm-Awad