samedi 18 avril 2015

How to load saved image in swift on ios simulator?

I save an image using this:



NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Image.png"];
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];


Then, I exit the app in the simulator. Then I attempt to load the image with this:



let imageName = "Image.png"
let image = UIImage(named: imageName)
i1.image = image


I can think of two reasons the image does not load:



  1. Exiting the app in the simulator is causing it to be uninstalled.

  2. I am not getting the paths correct in swift vs. obj-c.


Aucun commentaire:

Enregistrer un commentaire