如何毫无问题地从 Parse 获取自定义数据
How to get custom data from Parse without issues
如果你看这里 http://imgur.com/JJFvxXq 你可以看到我的问题。
if PFUser.currentUser()!.objectForKey("receivedItems") != nil && PFUser.currentUser()!.objectForKey("sentItems") != nil {
PFUser.currentUser()!.addObject(receivedItemsArr, forKey: "receivedItems")
PFUser.currentUser()!.addObject(sentItemsArr, forKey: "sentItems")
} else {
var qry = PFQuery()
receivedItemsArr = PFUser.currentUser()!.objectForKey("receivedItems") as! [GroceryItem]
sentItemsArr = PFUser.currentUser()!.objectForKey("sentItems") as! [GroceryItem]
}
如果自定义数组对象尚不存在,我想创建它,但是当我尝试在 else
语句中访问它时,它给了我这个错误
Warning: A long-running operation is being executed on the main thread.
Break on warnBlockingOperationOnMainThread() to debug.
fatal error: unexpectedly found nil while unwrapping an Optional value
并使应用程序崩溃。我必须使用 PFQuery 吗?我不知道怎么办!您能否提供有助于解决 else 语句中的错误并可能修复它的代码?
对于这个具体问题,这是一个逻辑问题。我必须将它从 != 切换到 == 才有意义
如果你看这里 http://imgur.com/JJFvxXq 你可以看到我的问题。
if PFUser.currentUser()!.objectForKey("receivedItems") != nil && PFUser.currentUser()!.objectForKey("sentItems") != nil {
PFUser.currentUser()!.addObject(receivedItemsArr, forKey: "receivedItems")
PFUser.currentUser()!.addObject(sentItemsArr, forKey: "sentItems")
} else {
var qry = PFQuery()
receivedItemsArr = PFUser.currentUser()!.objectForKey("receivedItems") as! [GroceryItem]
sentItemsArr = PFUser.currentUser()!.objectForKey("sentItems") as! [GroceryItem]
}
如果自定义数组对象尚不存在,我想创建它,但是当我尝试在 else
语句中访问它时,它给了我这个错误
Warning: A long-running operation is being executed on the main thread.
Break on warnBlockingOperationOnMainThread() to debug.
fatal error: unexpectedly found nil while unwrapping an Optional value
并使应用程序崩溃。我必须使用 PFQuery 吗?我不知道怎么办!您能否提供有助于解决 else 语句中的错误并可能修复它的代码?
对于这个具体问题,这是一个逻辑问题。我必须将它从 != 切换到 == 才有意义