Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jason Hernandez Berland
1,575 PointsIs this the right way to replace ! operator w/ optional and if let statement
So I'm using Parse as my backend and trying to update an object. Their docs call for the following:
var query = PFQuery(className:"GameScore")
query.getObjectInBackgroundWithId("xWMyZEGZ") {
(gameScore: PFObject!, error: NSError!) -> Void in
if error != nil {
NSLog("%@", error)
} else {
gameScore["cheatMode"] = true
gameScore["score"] = 1338
gameScore.saveInBackground()
}
}
My understanding of ! is that there is always a chance that your app can crash if the return comes back empty. thinking about changing to optional to safeguard:
var query = PFQuery(className:"GameScore")
query,getObjectInBackgroundWithId("xWMyZEGZ") {
(gameScore: PFObject?, error:NSError?) -> Void in?
Don;t even know how to form the let if statement with this one. Anyone?