Calling Swift Closure Inside Closure

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

I have the following code:

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


            twitterAPI?.getUserTimelin         


        
4条回答
  •  礼貌的吻别
    2021-01-08 01:19

    Swift 4

    Here is the simple example. But better to make an implementation through monad.

    ...
    guard let api = twitterAPI else { return }
    
    api.verifyCredentialsWithUserSuccessBlock({ userName, password in
        api.getUserTimelineWithScreenName(
            userName, 
            count: 100, 
            successBlock: { value in
                // success
            }) { error in 
                print("get user error: \(error)") 
            }
    }) { error in 
        print("verify error: \(error)") 
    }
    

提交回复
热议问题