【发布时间】:2023-03-14 15:43:02
【问题描述】:
我启用了local datastore in app delegate,我进行了查询,但是如果有no internet,我如何保存这些对象以查看它们?
这是我的查询:
query.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in
if error == nil && objects != nil
{
self.messages = objects!
for object in objects! {
inboxphotos.append(object.objectForKey("photo") as! PFFile)
inboxusers.append(object.objectForKey("username") as! String) }
}
}
现在我如何通过local query 来查看这个objects?
【问题讨论】:
-
你可以调用PFObject的
saveInBackgroundWithBlock方法将其保存到本地数据库,记住本地数据库必须在AppDelegate中启用。要检索数据,请创建 PFQuery 对象并调用findObjectsInBackgroundWithBlock方法。 -
@SuryakantSharma 我什么时候应该调用 saveInBackgroundWithBlock?在 findObjectsInBackgroundWithBlock 里面还是什么时候?
-
不!
findObjectsInBackgroundWithBlock用于使用PFQuery从 Parse DB 中获取对象,saveInBackgroundWithBlock用于保存。 -
@SuryakantSharma 你能回答我的问题并给我看一个简单的代码来获取带有查询的用户名并将其保存然后在没有互联网的情况下也显示在单元格上吗?
-
先告诉我,你卡在哪里了,到目前为止你做了什么?
标签: swift parse-platform pfquery