How to declare a block with arguments in swift?

ios, objective-c-blocks, swift

Solution

The equivalent of Objective-C blocks are swift closures, so it would go as follows

{ (user: PFUser, error: NSError) in
  if (!user) {
    println("Uh oh. The user cancelled the Facebook login.");
  } else if (user.isNew) {
    println("User signed up and logged in through Facebook!");
  } else {
    println("User logged in through Facebook!");
  }
}

Problem

Having a hard time figuring out how to properly declare/use blocks with swift. What would be the swift equivalent of the following code? Thanks. ``` ^(PFUser *user, NSError *error) { if (!user) { NSLog(@"Uh oh. The user cancelled the Facebook login."); } else if (user.isNew) { NSLog(@"User signed up and logged in through Facebook!"); } else { NSLog(@"User logged in through Facebook!"); } ```

Original source

Related problems