2

I'm currently storing my images directly in core data and experiencing issues when having to retrieve a high quality images.

I was advised to store the images in the document directory and save a path in core-data as to not store the actual images there but simply the address of where I can go and find it.

Can someone push me in the right direction? Can't seem to find the appropriate guidance?

Ramkrishna Sharma
  • 6,961
  • 3
  • 42
  • 51
Walking
  • 467
  • 1
  • 7
  • 23
  • this may help you http://stackoverflow.com/questions/2499176/ios-download-image-from-url-and-save-in-device – swiftBoy Mar 25 '16 at 13:36

3 Answers3

1

I was able to find the answers to all my questions in this youtube video - https://www.youtube.com/watch?v=6vk4UrJR8WM

This is the github with the file that has instructions as to how to complete this - https://github.com/TDAbboud/WeightLogger-Images

Walking
  • 467
  • 1
  • 7
  • 23
  • 1
    you should write the answer instead of posting links, in case those links were broken some day – yuji Apr 11 '19 at 06:50
0

Try Hanake cache: https://github.com/Haneke/Haneke It worked really well for me personally with the same problem. It makes a sometimes painful task pretty easy.

PyPiePi
  • 243
  • 2
  • 9
0

Save an image in Document directory is easy this code is not optimized is just for give you a hint( you should manage errors, optionals etc). Suppose that you already have a valid UIImage instance called image and a valid image name String called imageName

                let data = UIImagePNGRepresentation(image)
                // Unwrapping the data optional
                if let data = data {
                    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
                    let path = (paths.first! as! NSString).stringByAppendingPathComponent(imageName)
                    data.writeToFile(path, options: [])
                  //Save the path into your managed object
                    }
Andrea
  • 26,120
  • 10
  • 85
  • 131