Facebook recently updated Parse to support Swift. One example of the code that he gives is:
var gameScore = PFObject(className: "GameScore") gameScore.setObject(1337, forKey: "score") gameScore.setObject("Sean Plott", forKey: "playerName") gameScore.saveInBackgroundWithBlock { (success: Bool!, error: NSError!) -> Void in if success { NSLog("Object created with id: \(gameScore.objectId)") } else { NSLog("%@", error) } }
I am interested in this part: "(success: Bool !, error: NSError!)", In particular, the exclamation point item. My understanding of options was something like this:
NSError: This is an NSError and cannot be nil. NSError ?: this may include NSError or it may be zero, but you need to deploy it first. NSError !: this is a deployed force of NSError ?, and therefore cannot be nil.
On Facebook, an example says success is Bool! and the error is NSError! - that is, they are both guaranteed. Why aren't they just written as Bool and NSError if they opened Facebook before posting them? In addition, how can one establish both success and error? The traditional use of NSError will say that it is set to zero when there is no problem.
source share