iOS block with return value

前端 未结 2 595
孤独总比滥情好
孤独总比滥情好 2021-02-09 04:44

I am using a block from Facebook SDK. It returns a dictionary. I want that dictionary as a return value of a method. I am trying to wrap my head around the whole block concept b

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-09 05:26

    You already have it :)

    I would write a method to process the dictionary, in order to keep the completionHandler block a little cleaner--but you could write your response-handling code inside the block. As another commenter mentioned, this is async so you're not really "returning" anything...you're handling the completion block when it gets called.

    To help you understand a little, the completionHandler block in this case is a chunk of code that you're passing to the method as an argument, for it to call later. In essence, "whenever this call comes back, do this: ^{ ". The implementation of the FBRequest method will call your completionHandler (whatever that may be).

提交回复
热议问题