1

I have a couple of images with the url:

NSURL(string: "http://yxyxyxyx.com/images/events/flyer/xyxyxyxyx.png")

What's the best way to create an array with all images placed in /flyer/ using swift?

Help is very appreciated

David Seek
  • 16,783
  • 19
  • 105
  • 136

1 Answers1

0

A relatively basic way would be to get an array of image urls within flyer/. Then you can iterate over that array and fill another one with the results of UIImage(data: NSData(contentsOfURL: url)). However this is only recommended if there are very few images, and they are low resolution. If the images are too big run a significant risk of having iOS kill your app for using too much memory. It may be better to use something like Haneke Cache: https://github.com/Haneke/Haneke. If you cache the images one at a time, as you download them, you can keep your memory use reasonably low. Let me know if you have any questions!

PyPiePi
  • 243
  • 2
  • 9
  • there are only a few images and only 1-2 new images a month. my plan is to find the images, save them in core data and only ask if there is a new image to download. so I think I don't need Haneke. but I'll keep that in mind. – David Seek Feb 25 '16 at 17:22
  • are you able to give me code example for your solution? "an array of image urls within flyer/" don't really know how to implement that – David Seek Feb 25 '16 at 17:22
  • Yes, core data works just as well. Unfortunately I don't really know how to give you a code example as it depends on the way the web server works. Hopefully it is FTP, because HTTP would make this difficult. – PyPiePi Feb 25 '16 at 18:35
  • well it is a websire with http – David Seek Feb 25 '16 at 18:45
  • yes I already do that. my problem is, that this solution is only for one picture set with a hard coded link. I have several pictures unders /flyer/ and I need to get all of them and put them into an array – David Seek Feb 25 '16 at 18:47
  • If I understand correctly, you have a kind of listener for when new files are added, correct? So you could append the URL of the new image to an array of URLs. Once you have the array, you could listen to people on this thread: http://stackoverflow.com/questions/31828291/ios-keep-url-array-order-when-saving-images-into-an-array (or another like it). – PyPiePi Feb 25 '16 at 20:32