Calling Swift Closure Inside Closure

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

I have the following code:

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


            twitterAPI?.getUserTimelin         


        
4条回答
  •  旧时难觅i
    2021-01-08 01:20

    Ok, by the method names you are using, I'm guessing you are using the STTwitter library. If that's the case, you'll want something like this:

        if let twitterAPI = self.twitterAPI {
            twitterAPI.verifyCredentialsWithSuccessBlock({ (String) -> Void in
                twitterAPI.getUserTimelineWithScreenName("test", successBlock: { (objects: [AnyObject]!) -> Void in
                    println("success")
                    }, errorBlock: { (error: NSError!) -> Void in
                        println("failure")
                })
                }, errorBlock: { (error: NSError!) -> Void in
    
            })
        }
    

    Note the let call before using the optional self.twitterAPI variable.

提交回复
热议问题