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