In my creating of an app designed to mimic the photo app on the iphone itself, how would I create a local storage of the photos. I don't want the photos taken on the app to be saved to the camera roll or any other variation. How do I set up a storage system for the app itself to hold photos taken?
Asked
Active
Viewed 1,292 times
2
-
Here is an excellent solution : [Save images in NSUserDefaults?](http://stackoverflow.com/questions/6648518/save-images-in-nsuserdefaults) – Bista Mar 20 '15 at 04:30
-
1@UmangBista DO NOT use `NSUserDefaults` to save images. – rmaddy Mar 20 '15 at 04:32
-
Simply save the images to the Documents folder or some other appropriate location within the app's sandbox. – rmaddy Mar 20 '15 at 04:33
-
@maddy - have you opened the given link? It provides both solutions saying NSUserdefaults(Not Recommended). And do not comment twice, rather edit previous comment.95K :) – Bista Mar 20 '15 at 04:35
-
@UmangBista So basically replace the NSUserDefaults with the Documents folder in the build? Sorry I'm horribly new to ios programming. Which is precisely the reason why such a simple app is boggling me right now. Also, if either of you have a good starter guide to reference me to creating this photo app, any help would be greatly appreciated! :) – Ryan T Mar 20 '15 at 04:54
-
@UmangBista, then first of all you should update your comment properly. You're pointing to a link of a question which one asking whether to use `NSUserDefaults` or not. Is OP asked you for this in his question? You should comment like, Checkout this [question](http://stackoverflow.com/questions/6648518/save-images-in-nsuserdefaults). Currently your comment create confusion for a newbie. – Hemang Mar 20 '15 at 05:10
-
@hagile - agreed. #Ryan T - as 'hagile' said, I got you confused. Use 'document folder' rather than 'NSUserDefaults'. Can't help more. :) – Bista Mar 20 '15 at 05:16
2 Answers
1
As @rmaddy commented you should store your images into your apps document directory with unique name for it and store that name some where so that next time you can simply get an image out of the document directory by using particular image name. As you're commented you're new to iOS programming, I suggest you to learn SQLite or CoreData structure to manage your app data. SQLite will be easy for you. At this point, I'm not recommending but you can store those file names (and no the images) into NSUserDefaults
too.

Hemang
- 26,840
- 19
- 119
- 186
-
Okay that makes sense. So adding to that, if I want to access the data from the app I just pull from that directory to display it in a gallery style UI right? – Ryan T Mar 22 '15 at 05:38
0
You CAN save image using CoreData and thats simple and neat.
- Set the attribute type to 'Binary data' when you config the .xcdatamodel file.
Convert the UIImage to NSData before saving
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(<UIImage>)];
That's it! Now you can directly save the image to your entity.

Pang Ho Ming
- 1,299
- 10
- 29