<small id='L3jvZ'></small><noframes id='L3jvZ'>

  • <tfoot id='L3jvZ'></tfoot>

          <bdo id='L3jvZ'></bdo><ul id='L3jvZ'></ul>
      1. <i id='L3jvZ'><tr id='L3jvZ'><dt id='L3jvZ'><q id='L3jvZ'><span id='L3jvZ'><b id='L3jvZ'><form id='L3jvZ'><ins id='L3jvZ'></ins><ul id='L3jvZ'></ul><sub id='L3jvZ'></sub></form><legend id='L3jvZ'></legend><bdo id='L3jvZ'><pre id='L3jvZ'><center id='L3jvZ'></center></pre></bdo></b><th id='L3jvZ'></th></span></q></dt></tr></i><div id='L3jvZ'><tfoot id='L3jvZ'></tfoot><dl id='L3jvZ'><fieldset id='L3jvZ'></fieldset></dl></div>
        <legend id='L3jvZ'><style id='L3jvZ'><dir id='L3jvZ'><q id='L3jvZ'></q></dir></style></legend>
      2. 使 iOS 块同步执行

        Make iOS blocks execute synchronously(使 iOS 块同步执行)

            <i id='k4voi'><tr id='k4voi'><dt id='k4voi'><q id='k4voi'><span id='k4voi'><b id='k4voi'><form id='k4voi'><ins id='k4voi'></ins><ul id='k4voi'></ul><sub id='k4voi'></sub></form><legend id='k4voi'></legend><bdo id='k4voi'><pre id='k4voi'><center id='k4voi'></center></pre></bdo></b><th id='k4voi'></th></span></q></dt></tr></i><div id='k4voi'><tfoot id='k4voi'></tfoot><dl id='k4voi'><fieldset id='k4voi'></fieldset></dl></div>
            <tfoot id='k4voi'></tfoot>

            <small id='k4voi'></small><noframes id='k4voi'>

                <tbody id='k4voi'></tbody>

                • <bdo id='k4voi'></bdo><ul id='k4voi'></ul>
                • <legend id='k4voi'><style id='k4voi'><dir id='k4voi'><q id='k4voi'></q></dir></style></legend>
                • 本文介绍了使 iOS 块同步执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何让一个block同步执行,或者让函数在return语句之前等待handler,这样数据才能从block传回来?

                  How can I make a block execute synchronously, or make the function wait for the handler before the return statement, so the data can be passed back from the block?

                  -(id)performRequest:(id)args
                  {
                  __block NSData *data = nil;   
                  
                      [xyzclass requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
                          data = [NSData dataWithData:responseData];
                      }];
                  
                      return data;
                  }
                  

                  推荐答案

                  在这种情况下你可以使用信号量.

                  You can use semaphores in this case.

                  -(id)performRequest:(id)args
                  {
                      __block NSData *data = nil;   
                       dispatch_semaphore_t sem = dispatch_semaphore_create(0);
                       [xyzclass requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
                         data = [NSData dataWithData:responseData];
                         dispatch_semaphore_signal(sem);
                       }];
                      dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
                      return data;
                  }
                  

                  信号量将阻止进一步语句的执行,直到收到信号,这将确保您的函数不会过早返回.

                  semaphore will block execution of further statements until signal is received, this will make sure that your function does not return prematurely.

                  这篇关于使 iOS 块同步执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                  Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                  ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                  How to get indexPath.row of tableView which is currently being displayed?(如何获取当前正在显示的 tableView 的 indexPath.row?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)
                    <i id='GzVej'><tr id='GzVej'><dt id='GzVej'><q id='GzVej'><span id='GzVej'><b id='GzVej'><form id='GzVej'><ins id='GzVej'></ins><ul id='GzVej'></ul><sub id='GzVej'></sub></form><legend id='GzVej'></legend><bdo id='GzVej'><pre id='GzVej'><center id='GzVej'></center></pre></bdo></b><th id='GzVej'></th></span></q></dt></tr></i><div id='GzVej'><tfoot id='GzVej'></tfoot><dl id='GzVej'><fieldset id='GzVej'></fieldset></dl></div>

                  1. <tfoot id='GzVej'></tfoot>

                    <legend id='GzVej'><style id='GzVej'><dir id='GzVej'><q id='GzVej'></q></dir></style></legend>

                      <tbody id='GzVej'></tbody>
                  2. <small id='GzVej'></small><noframes id='GzVej'>

                          <bdo id='GzVej'></bdo><ul id='GzVej'></ul>