Search code examples
arraysswiftparse-platformrelationships

Parse and Swift Relations, is this correct?


I have been trying to understand Parse relationships and I'm still not sure if I'm getting them right, please bear with me.

I have an app that downloads data from different countries, as of now, it simply downloads the names and puts them on a tableview, when you click on a cell it takes you to a detailview that shows a scrollview with 3 different images from the country selected, the problem with this is that it is hard to scale it to add more images.

In Parse, I have three columns (image1,image2,image3) and on my app I simply run a Query that adds them into an array, then my scrollview goes through them when you swipe. What I need to to is to be able to add any number of images I want without adding more columns in parse and I thought I could do it like this:

Create an array in Parse, I name it "ImageSet", this image set belongs to a country, so in the "Country" class I have the name of the country, then the ImageSet array.

Image

Then I create a class named "Images",this class will have two columns, "Name" and "Image". In my app I will assign the "Country" array to all of the images in the "Images" class that has the same name.

enter image description here

Lets say I add a new Image with the name "Albania" to the images class, In my app I run a query that gets the images, then if they have the same name as the country name, they will get added to the array of the "Country" class. Is this even possible? or am I getting everything wrong here?


Solution

  • Don't use an array. Simply do this,

    have a table "Countries" which has a column "name" being a country name

    have a table "CountryImages" which has two columns. One is a pointer to a Country, and the other is a PFImage.

    Note that it's difficult to know precisely what you are trying to achieve, but, in the first instance you should master the simple basic technique I explain above.

    Note that this will only take a matter of thirty seconds to try, so try it and see how you go from there.