How do I return a variable from a block inside a method?

后端 未结 3 1937

Say I have this method that given a URL returns a UIImage:

- (void)getUIImageFromURL:(NSURL *)URL {
    NSURLRequest *request = [NSURLRequest requestWithURL:         


        
3条回答
  •  情深已故
    2020-12-12 08:41

    You are calling an asynchronous method with two blocks for handling success and failure. By the time one of these handlers is called, your calling method is long gone. It doesn't make any sense to think you could return data to it, because it is gone.

    In the success block and failure block, you give instructions what to do when the operation has succeeded or failed. There is nobody there to return anything to. What you do is add code in the block to process and store the result of success in the right place, or to handle errors in the correct way.

提交回复
热议问题