7

So far I am having issues with blocks like this:

user.signUpInBackgroundWithBlock {
        (succeeded: Bool!, error: NSError!) -> Void in
        if error == nil {
            println("success")
        } else {
            println("\(error)");
            // Show the errorString somewhere and let the user try again.
        }
    }

When I add this into Xcode I get this:

Cannot invoke 'signUpInBackgroundWithBlock' with an argument list of type '((Bool!, NSError!) -> Void)'

When I run this code in Xcode 6.3 (non beta) it works fine. But in the Beta it fails and wont allow me to build. Any ideas if this will be cleared up or if there is a different implementation that I could use. Ive tried using just the signUpInBackgroundWithTarget but Im just not able to access the error correctly if one is received.

5 Answers 5

9

be sure you are using SDK version 1.7.1, then removing the types from your closure should do the trick:

user.signUpInBackgroundWithBlock { (succeeded, error) -> Void in
    if error == nil {
        println("success")
    } else {
        println("\(error)");
        // Show the errorString somewhere and let the user try again.
    }
}
Sign up to request clarification or add additional context in comments.

Comments

2

Due to the new addition of "Nullability Annotations" to Swift 1.2, you have to rewrite the code above like this (using Parse 1.7.1+):

user.signUpInBackgroundWithBlock { (succeeded: Bool, error: NSError?) -> Void in
    if let error = error {
        println(error) // there is an error, print it
    } else {
        if succeeded {
            println("success")
        } else {
            println("failed")
        }
    }
}

Parse is now returning optionals (?) instead of explicitely unwrapped objects (!).

2 Comments

Strange, but Xcode show me error: Cannot invoke 'signUpInBackgroundWithBlock' with an argument list of type '((Bool, NSError?) -> Void)'
@orkenstein are you on at least Parse 1.7.1?
1

Notation of Swift is changed

class AAPLList : NSObject, NSCoding, NSCopying { 
    // ...
    func itemWithName(name: String!) -> AAPLListItem!
    func indexOfItem(item: AAPLListItem!) -> Int

    @NSCopying var name: String! { get set }
    @NSCopying var allItems: [AnyObject]! { get }
    // ...
}

After annotations:

class AAPLList : NSObject, NSCoding, NSCopying { 
    // ...
    func itemWithName(name: String) -> AAPLListItem?
    func indexOfItem(item: AAPLListItem) -> Int

    @NSCopying var name: String? { get set }
    @NSCopying var allItems: [AnyObject] { get }
    // ...
}

So you can change

(succeeded: Bool!, error: NSError!) -> Void in

to

(success: Bool, error: NSError?) -> Void in

Comments

0

Which Parse SDK are you using? They released version 1.7.1 a few days ago that should fix your issue.

3 Comments

Is there anything special I need to do to upgrade to 1.7.1? I removed 1.7.0 and dragged in 1.7.1 and I still get the same error
Nope....it says in the release notes that it should of fixed your problem so it might be something on the Xcode side of things
Ok, I may try start a new project with it from scratch and see if I get it. Thanks though.
0

Change:

(succeeded: Bool!, error: NSError!) -> Void in

to

(succeeded, error) -> Void in

This change is required due to changes in the Parse SDK

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.