Reputation: 345
After updating to the latest Parse SDK 1.8.5, I am receiving two errors surrounding the findObjectsInBackgroundWithBlock
function. Two errors return on the same line:
if let objects = query.findObjects() as? [PFObject]
I have tried changing it to as [PFObject]?
with no luck. The errors are as follows:
Call can throw, but it is not marked with 'try' and the error is not handled
AND Conditional cast from '[PFObject]' to '[PFObject]' always succeeds
query.findObjectsInBackgroundWithBlock { (objects: [PFObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = query.findObjects() as? [PFObject] {
for object in objects {
object.deleteInBackgroundWithBlock{ (success, error) -> Void in
if (success) {
print("Worked")
print(objects.count)
self.viewDidAppear(true)
} else {
}
}
I have researched similar problems, and tried to fix it to query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
but this has done nothing either.
I am not sure how to fix either of these errors, and am very confused as to why they suddenly popped up. All of my functions were running perfectly, and have been for weeks, and suddenly these errors have popped up.
changing it from:
if let objects = query.findObjects() as? [PFObject]
to
if let objects = objects as [PFObject]?
seemed to fix the problem, but I am not sure if it is now going to run properly.
For other lines with the same error, XCode suggested changing it to:
self.rooms = (results as [PFObject]?)!
and that took away the error. I am pretty new to Swift coding, so I am not sure exactly what has happened, if anyone has any insight?
Upvotes: 2
Views: 461
Reputation:
Removing as [PFObject]?
from if let objects = objects as [PFObject]?
should solve your conditional cast error.
Upvotes: 0
Reputation: 2666
Using findObjects()
is much more difficult with the new update. This is because with Xcode 7 and Swift 2, Swift became better at handling errors and Parse took advantage of these new methods to allow findObjects()
to throw an error. It would be your job to handle the error and provide other code to run in case of such an error. In addition to these new requirements, findObjects()
runs synchronously and will slow down your app. You should be using findObjectsInBackground()
which runs asynchronously. This will solve both of your problems. If you need hep implementing this function, there is a lot of documentation and question/answers online.
Upvotes: 2