2015-04-04 58 views
7

到目前爲止,我有問題的工作與塊這樣的:解析SDK方法不是在Xcode 6.3 Beta版

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. 
     } 
    } 

當我添加到Xcode的這個我得到這個:

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

當我運行這個代碼在Xcode 6.3(非測試版)中工作正常。但在測試版中,它失敗了,不會讓我建立。任何想法,如果這將被清除,或者如果有一個不同的實現,我可以使用。我曾嘗試使用signUpInBackgroundWithTarget,但我只是無法正確訪問錯誤,如果收到。

回答

0

您使用哪個Parse SDK?他們幾天前發佈了1.7.1版本,可以解決您的問題。

+0

有什麼特別的,我需要做升級到1.7.1?我刪除了1.7.0,並在1.7.1中拖動,我仍然得到相同的錯誤 – 2015-04-04 20:57:45

+0

不......它在發行說明中說它應該修復你的問題,所以它可能是東西的東西 – nick9999 2015-04-04 20:58:33

+0

好吧,我可以嘗試從頭開始一個新項目,看看我是否能夠得到它。不過謝謝。 – 2015-04-04 20:59:18

9

確保您使用的SDK版本1.7.1,然後取出從封閉的類型應該做的伎倆:

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

這對我來說詭計!謝謝! – AndyDev 2015-04-09 02:03:49

2

由於新增加的「空性集註」斯威夫特1.2,你必須重寫上面的代碼所示(使用解析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") 
     } 
    } 
} 

解析現在返回自選的,而不是明確地展開對象(?)(!)。

+0

奇怪,但Xcode顯示錯誤:'不能用類型爲'((Bool,NSError?) - > Void)'的參數列表調用'signUpInBackgroundWithBlock'' – orkenstein 2015-08-16 08:40:26

+0

@orkenstein你至少在Parse 1.7.1上? – 2015-08-17 16:08:28

0

變化:

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

(succeeded, error) -> Void in 

這需要改變由於斯威夫特的解析SDK

1

符號的變化改變

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 } 
    // ... 
} 

後註釋:

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 } 
    // ... 
} 

所以,你可以改變

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

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