Parse SDK methods not working in Xcode 6.3 Beta

前端 未结 5 1762
夕颜
夕颜 2021-01-12 13:39

So far I am having issues with blocks like this:

user.signUpInBackgroundWithBlock {
        (succeeded: Bool!, error: NSError!) -> Void in
        if erro         


        
相关标签:
5条回答
  • 2021-01-12 13:51

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

    0 讨论(0)
  • 2021-01-12 14:05

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

    0 讨论(0)
  • 2021-01-12 14:07

    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.
        }
    }
    
    0 讨论(0)
  • 2021-01-12 14:13

    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

    0 讨论(0)
  • 2021-01-12 14:14

    Change:

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

    to

    (succeeded, error) -> Void in
    

    This change is required due to changes in the Parse SDK

    0 讨论(0)
提交回复
热议问题