IOS convert asynchronous block to run synchronously

Source: Internet
Author: User
Use dispatch_semaphore_t to implement dispatch_semaphore_t sema = dispatch_semaphore_create (0); Create semaphore __block Alassetsgroup *ret = nil; Alassetslibrarygroupsenumerationresultsblock Listgroupblock = ^ (Alassetsgroup *group, BOOL *stop) {ret = group; dispatch _semaphore_signal (SEMA); Key point, send the semaphore here}; Alassetslibraryaccessfailureblock Failureblock = ^ (Nserror *error) {ret = nil; dispatch_semaphore_signal (SEMA);//Key points, Failed to send}; Nsuinteger grouptypes = Alassetsgroupsavedphotos; [Self.assetslibrary enumerategroupswithtypes:grouptypes Usingblock:listgroupblock FailureBlock:failureBlock]; Dispatch_semaphore_wait (Sema, dispatch_time_forever); The key point, which waits for the semaphore return RET; This article is translated by Tony, Link: Convert async block to sync | Waterworld Http://www.waterworld.com.hk/en/blog/convert-async-block-sync Turn: http://itony.me/65.html

IOS convert asynchronous block to run synchronously

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.