zoukankan      html  css  js  c++  java
  • iOS 转换异步block为同步方式运行

    使用dispatch_semaphore_t 实现 dispatch_semaphore_t sema = dispatch_semaphore_create(0); //创建信号量 __block ALAssetsGroup *ret = nil; ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) { ret = group; dispatch_semaphore_signal(sema); //关键点,在此发送信号量 }; ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError *error) { ret = nil; dispatch_semaphore_signal(sema); //关键点,失败时发送 }; NSUInteger groupTypes = ALAssetsGroupSavedPhotos; [self.assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failureBlock]; dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); //关键点,在此等待信号量 return ret; 本文由Tony翻译,原文链接:Convert async block to sync | Waterworld http://www.waterworld.com.hk/en/blog/convert-async-block-sync 转:http://itony.me/65.html
  • 相关阅读:
    centos部署bladex boot 之docker安装
    git ssh key创建和github使用
    Debian root登录设置
    Linux软件源
    Secure backup
    Python简易web服务
    好久没有更新博客了
    Python实现无向图最短路径
    DWZ使用中遇到的坑
    tronado学习
  • 原文地址:https://www.cnblogs.com/ygm900/p/4551317.html
Copyright © 2011-2022 走看看