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?
Suppose you are using an asynchronous block from the ALAssetsLibrary API such as enumerateGroupsWithTypes:ALAssetsGroupAll
Share
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:
So in this case just look for that nil!
EDIT:
To check for nil try something like this
And if you want to check if you are currenty on the main thread you can use:
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.