Home » Swift » What to do with Swift's “try?” that cause “Result of try? is unused”? [duplicate]

What to do with Swift's “try?” that cause “Result of try? is unused”? [duplicate]

Posted by: admin November 30, 2017 Leave a comment

Questions:

This question already has an answer here:

Answers:

As your requirement, “At the same time I don’t care about the exception that may be thrown, I just want to call method”, do this:

try! managedObjectContext.save()

But it will crash if an error is thrown. So, use below code snip for safe:

_ = try? managedObjectContext.save()

Questions:
Answers:

I think you need something like this.

Do {
 try managedObjectContect.Save()
}
catch let error {
   print("error")
}