Saving images to master data

I am new to basic data. Can someone help me provide the right steps / tutorial showing how to save images for master data and reuse them too. I can store the string data already, but my application crashes when I try to save the image. To save:

DataEvent *event = (DataEvent *)[NSEntityDescription insertNewObjectForEntityForName:@"DataEvent" inManagedObjectContext:managedObjectContext]; NSURL *url2 = [NSURL URLWithString:@"xxxxxxxxxxxxxxx SOME URL xxxxxxxxxxxx"]; NSData *data = [[NSData alloc] initWithContentsOfURL:url2]; imageSave=[[UIImage alloc]initWithData:data]; NSData * imageData = UIImageJPEGRepresentation(imageSave, 100.0); [event setValue:self.imageSave forKey:@"pictureData"]; 

Recovery:

  DataEvent *event = (DataEvent *)[eventsArray objectAtIndex:indexPath.row]; UIImage *image = [UIImage imageWithData:[event valueForKey:@"pictureData"]]; UIImageView *imageViewMainBackGround = [[UIImageView alloc] CGRect rect3=CGRectMake(0,2,100.0,100.0); imageViewMainBackGround.frame = rect3; [cell.contentView addSubview:imageViewMainBackGround]; [imageViewMainBackGround release]; 
+6
source share
4 answers

To save:

 NSData *imageData = UIImagePNGRepresentation(myUIImage); [newManagedObject setValue:imageData forKey:@"imageKey"]; 

A To return the image:

 NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath]; UIImage *image = [UIImage imageWithData:[selectedObject valueForKey:@"imageKey"]]; [[newCustomer yourImageView] setImage:image]; 

modified format

+9
source

error: reason = "The model used to open the store is not compatible with the one used to create the store

Decision:

remove the assembly project from the simulator and clear it from the Product tab, now run the project.

+2
source

Do not change the resolution if it is not necessary ..

 NSData * imageData = UIImageJPEGRepresentation(imageSave, 0.0); 

// and change the next line

 [event setValue:imageData forKey:@"pictureData"]; 

See the repository and extract the image from the master data tutorial with sample code.

Hope this helps you.

+1
source

You should set the pictureData strong> value of your NSData managed object (in your case imageData strong>), not the imageSave object, which is a UIImage.

0
source

Source: https://habr.com/ru/post/914098/


All Articles