Calling Swift Closure Inside Closure

前端 未结 4 1231
礼貌的吻别
礼貌的吻别 2021-01-08 00:26

I have the following code:

  twitterAPI?.verifyCredentialsWithUserSuccessBlock({ (userName, password) -> Void in


            twitterAPI?.getUserTimelin         


        
4条回答
  •  星月不相逢
    2021-01-08 01:15

    Try:

            twitterAPI?.verifyCredentialsWithUserSuccessBlock({ (userName, password) -> Void in
                self.twitterAPI?.getUserTimelineWithScreenName(userName, successBlock: { (objects :[AnyObject]!) -> Void in
    
                    }, errorBlock: { (error :NSError!) -> Void in
                })
    
                return  // <-- ADDED
    
                }, errorBlock: { (error :NSError!) -> Void in
            })
    

    In this case

    { (userName, password) -> Void in
        self.twitterAPI?.getUserTimelineWithScreenName("", successBlock: { (objects :[AnyObject]!) -> Void in
        }, errorBlock: { (error: NSError!) -> Void in
        })
    }
    

    is a "single expression closure" that has implicit non Void return.

    As of Xcode 6.2 / Swift 1.1, you need explicit return here.

    Or, use Xcode 6.3 / Swift 1.2 that has fixed this problem.

    See this question: One-line closure without return type or Swift - 'Bool' is not a subtype of 'Void'?

提交回复
热议问题