title: How to update parse records when using sub classes
body: <p>I have a parse.com backend. I have a Message class which is a subclass of PFObject. I store the messages from the db in an array messages = Message.</p>
  
  <p>Im having trouble when I need to update the records as Im getting duplicates.</p>
  
  <p>What I've been trying to do is get a message from the messages array and then call saveInBackgroundWithBlock... thinking the backend will know its referring to an existing row in the db.</p>
  
  <p>I've also just come across fetchIfNeeded.</p>
  
  <p>My code is below. Where am I going wrong? How should I update existing records that are stored locally in an array of messages. How should I be using fetchIfNeeded in my scenario, if at all? Or should I be using core data / local storage in some way? (confused)</p>
  
  <pre><code>class Message : PFObject, PFSubclassing {
   var messageTitle : NSString
   var imageFile: PFFile   
  }
  
  func getMessages() {}
   var currentMessages = [Message]()
   var messageQuery = Message.query()
   messageQuery.findObjectsInBackgroundWithBlock { (objects: [AnyObject]!, error: NSError!) -&gt; Void in
    for object in objects {
     var message = Message()
     message.messageTitle = object["messageTitle"] as String
     message.imageFile = object["imageFile"] as PFFile
     self.currentMessages.append(message)
    }
  }
  
  func updateMessage() {
   message.messageTitle = self.messageTitle.text
   let imageData = UIImagePNGRepresentation(self.imageToPost.image)
   let imageFile = PFFile(name: "image.png", data: imageData)
   message.imageFile = imageFile
   message.saveInBackgroundWithBlock({ (success: Bool!, error: NSError!) -&gt; Void in
    if success == false {
     self.displayAlert("Something went wrong", error: "Please try again later")
    } else {
     self.navigationController?.popViewControllerAnimated(true)
    }
   })
  }
  
  func saveNewMessage() {
   message = Message()
   message.messageTitle = messageTitle.text
   let imageData = UIImagePNGRepresentation(self.imageToPost.image)
   let imageFile = PFFile(name: "image.png", data: imageData)
   message.imageFile = imageFile
   message.saveInBackgroundWithBlock({ (success: Bool!, error: NSError!) -&gt; Void in
    if success == false {
     self.displayAlert("Something went wrong", error: "Please try again later")
    } else {
     self.navigationController?.popViewControllerAnimated(true)
    }
   })
  }
  </code></pre>