gpt4 book ai didi

ios - 解析本地数据存储仅返回一个对象

转载 作者:行者123 更新时间:2023-11-30 13:51:46 24 4
gpt4 key购买 nike

我有以下代码:

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;
}
}

它可以很好地保存到 Parse 的服务器上。播客剧集也会在本地保存,但播客本身会覆盖我之前保存的任何其他播客,导致我的表格 View 始终仅加载 1 个条目。我认为这可能是由于以下原因(取自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.

但是我不知道如何解决这个问题。

我正在运行 Parse 1.10.0

最佳答案

您的代码有拼写错误。

替换这个:

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

这样:

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

关于ios - 解析本地数据存储仅返回一个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34184183/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com