Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7457981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:23:28+00:00 2026-05-29T13:23:28+00:00

Suppose you are using an asynchronous block from the ALAssetsLibrary API such as enumerateGroupsWithTypes:ALAssetsGroupAll

  • 0

Suppose you are using an asynchronous block from the ALAssetsLibrary API such as enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop). First off, Since the block is asynchronous, does this mean the system will automatically run the block on a separate thread of execution? If so, what is the best way to know when the block will be completed so I could perform some action like stopping an UIActivityIndicator from spinning or reloading a UITableView. IE like the animateWithDuration block which has a completion block that allows you to perform some action when the animation is complete. What is the pattern for doing something similar here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:23:29+00:00Added an answer on May 29, 2026 at 1:23 pm

    A block will usually run on your main thread, the function that you are calling is the asynchronous part. The block is often used to know when the function you called asynchronously is completed. In this particular case, a quick look at the reference material tells us that:

    The block to invoke using each asset in turn. When the enumeration is
    done, enumerationBlock is invoked with group set to nil.

    So in this case just look for that nil!

    EDIT:

    To check for nil try something like this

    ALAssetsLibrary *lib = [ALAssetsLibrary new];
    [lib enumerateGroupsWithTypes:ALAssetsGroupAll 
                       usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                           if (group == nil) {
                               NSLog(@"Done!");
                           }
                       } 
                     failureBlock:^(NSError *error) {
                         NSLog(@"Failed...");
                     }
     ];
    

    And if you want to check if you are currenty on the main thread you can use:

     NSLog("On main thread : %d",[NSThread isMainThread] ? 1:0);
    

    In API calls like this the block in run on the main thread because they are not the “heavy lifting” part of the function. They code that could potentially lock up your UI is still done in the background. In this particular case, its more that the function is “coming back up for air” and asking you what you want done for the given group, and then it goes back in the background.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In .Net, suppose I instantiate an object that starts an asynchronous process (using Delegate.BeginInvoke
Suppose I'm using transactional replication to replicate articles from one server to another (
How can we get details from twitter and face book using PHP suppose think
Let's suppose I'm using the Northwind database and I would like to run a
Suppose I write a program using immutable data structures in Java. Even though it
Suppose this C# code: using (MemoryStream stream = new MemoryStream()) { StreamWriter normalWriter =
Suppose I have the following: using(var ctx = DataContextFactory.Create(0)) { ... Some code ...
Suppose I want to open a file in an existing Emacs session using su
Suppose I let the user to write a condition using Javascript, the user can
Suppose I am executing several queries on the server using mysql_query . The results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.