If you look here https://i.sstatic.net/bJGW2.jpg you can see my issue.
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]
}
I want to make a custom array object if it doesn't exist yet, but when I try to access it in the else
statement , it gives me this error
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
and crashes the app . Do I have to use a PFQuery? I don't know how to! could you help with code that would help with the error in the else statement and possibly fix it?
for this specific question, it was a logic problem. i had to swithc it from != to == for it to make sense