0
votes

I have the following code:

var episodesToSendToParse = [PFObject]()
let currentPodcast = PFObject(className: "Podcast")

currentPodcast["name"] = name
currentP["user"] = PFUser.currentUser()

for episode in episodes {
  let episodes2 = PFObject(className: self.episodesClass)
  episodesToParse["title"] = episode.title
  episodesToParse["parent"] = currentPodcast
  episodesToSendToParse.append(episodes2)
}

PFObject.pinAllInBackground(episodesToSendToParse).continueWithBlock { (task: BFTask!) -> AnyObject! in
        if let error = task.error {
            print(error)
            return task;
        }
        print("finished pinning")
        return task;
    }

PFObject.saveAllInBackground(episodesToSendToParse).continueWithBlock { (task: BFTask!) -> AnyObject! in
        if let error = task.error {
            print(error)
            return task;
        }
        NSNotificationCenter.defaultCenter().postNotificationName("podcastSaved", object: self)
        print("finished saving")
        return task;
    }
}

It saves fine to Parse's servers. The podcast episodes also save locally but the podcast itself overwrites any other podcast I had previously saved, causing my tableview to always load 1 entry only. I thought this may be because of the following (taken from parse.com):

There are a couple of side effects of enabling the local datastore that you should be aware of. When enabled, there will only be one instance of any given PFObject. For example, imagine you have an instance of the "GameScore" class with an objectId of "xWMyZ4YEGZ", and then you issue a PFQuery for all instances of "GameScore" with that objectId. The result will be the same instance of the object you already have in memory.

However I have no idea how to remedy this.

I am running Parse 1.10.0

2
The note is about other thing. It means that if you change and save instance of PFObject, then local data store won't store old and new instances, only new instead. - Juri Noga

2 Answers

0
votes

You have typo in code.

Replace this:

for episode in episodes {
  let episodes = PFObject(className: self.episodesClass)
  episodesToParse["title"] = episode.title
  episodesToParse["parent"] = currentPodcast
  episodesToSendToParse.append(episodesToParse)
}

With this:

for episode in episodes {
  let episodes = PFObject(className: self.episodesClass)
  episodes["title"] = episode.title
  episodes["parent"] = currentPodcast
  episodesToSendToParse.append(episodes)
}
0
votes

This is a Parse bug. See: #535

Using pinAllInBackground(objects: [PFObject]?, withName: String) is a workaround.