Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse SDK methods not working in Xcode 6.3 Beta

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.

like image 420
Jason Storey Avatar asked Apr 04 '15 01:04

Jason Storey


Video Answer


3 Answers

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.
    }
}
like image 146
wfbarksdale Avatar answered Oct 26 '22 08:10

wfbarksdale


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 (!).

like image 33
Van Du Tran Avatar answered Oct 26 '22 08:10

Van Du Tran


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

like image 36
NewPlayerX Avatar answered Oct 26 '22 08:10

NewPlayerX