Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Martin Dweh
Martin Dweh
1,014 Points

Fetching JSON images from my own website into a CollectionView

I'm having a little problem with what I want to do;

I have my own website with some pictures in a folder, that I want to display in an App within a CollectionView that has 7 sections.

7 Sections and each section have 4 cells/images. The collectionView works fine, it displays the images from within my project.

-But the App is large in size.

So now I simply want to get/fetch the images from my website and have the collectionView works the exact same way it's working now.

when I tapped on a cell, it goes to another view; "detailView" and displays the selected cell's image larger.

When I pressed hard on a cell, it goes to that same view; "detailView" and displays the selected cell's image larger.

also, I want it to save the images, so it doesn't download them every time the user opens the App. And I want to be about to add NEW images to the ones on my site and they automatically show up in the app when the user refresh the collectionView

The question here is; How do I go about setting this up in swift 3. fetching from my own website? Can you please help me with a sample code.

  • I have everything else working, except the JSON fetching from my own website.

thank you very much for your time and your help
// JSON Document {

"PhotosAlbumOne": [ { "sectionName": "Monday's Photos", "photoImage": "mphoto01.jpg", "imageNameLabel": "DayOneEvent", }, { "sectionName": "Monday's Photos", "photoImage": "mphoto02.jpg", "imageNameLabel": "DayOneEvent", }, { "sectionName": "Monday's Photos", "photoImage": "mphoto03.jpg", "imageNameLabel": "DayOneEvent", }, { "sectionName": "Monday's Photos", "photoImage": "mphoto04.jpg", "imageNameLabel": "DayOneEvent", }, ], "PhotosAlbumTwo": [ { "sectionName": "Tuesday's Photos", "photoImage": "Tphoto01.jpg", "imageNameLabel": "DayTwoEvent", }, { "sectionName": "Tuesday's Photos", "photoImage": "Tphoto02.jpg", "imageNameLabel": "DayTwoEvent", }, { "sectionName": "Tuesday's Photos", "photoImage": "Tphoto03.jpg", "imageNameLabel": "DayTwoEvent",​ }, { "sectionName": "Tuesday's Photos", "photoImage": "Tphoto04.jpg", "imageNameLabel": "DayTwoEvent",​ }, ], ​

} This JSON goes up to PhotosAlbumSeven