iosswiftparse-platformpffilepfimageview

How to add another column to my class in Parse.com? (Swift)


I am having some difficulty adding a new column to my class in Parse. Currently I have made a class (named: Venue Data) with the name and geopoints of restaurants. I would like to add to that class a column for image which will be paired respective to the specific restaurant. I am quite stumped as to how I should go about it. Any help is greatly appreciated.


Solution

  • Parse allows you to add columns to a class lazily, meaning that you can add a field to your PFObject and if it is not present in your Parse class, Parse will add that column for you.

    Here's how you would add a column via code:

    // Prepare image
    let imageData = UIImagePNGRepresentation(yourImage)
    let imageFile = PFFile(name:"image.png", data:imageData) // "image.png" is the name which would be shown on Parse.com
    
    // Add the new field to your object
    yourObject["image"] = imageFile
    yourObject.saveInBackground()
    

    You'll notice that Parse will create a new column named image on their web portal.