tags:

views:

315

answers:

1

Hi ,

I have a issue with enumerationblock , when i try to access the vidoes and audios from the phone using iPhone OS 4.0, i found the following api from the class AssetsLibrary

Invokes a given block passing as a parameter each of the asset groups that match the given asset group type.

- (void)enumerateGroupsWithTypes:(ALAssetsGroupType)types
                      usingBlock:(ALAssetsLibraryGroupsEnumerationResultsBlock)enumerationBlock
                    failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock

The signature for the ALAssetsLibraryGroupsEnumerationResultsBlock is given as follows :

typedef void (^ALAssetsLibraryGroupsEnumerationResultsBlock)(ALAssetsGroup *group, BOOL *stop);

SO how can i create a ALAssetsLibraryGroupsEnumerationResultsBlock for passing as a parameter for the above method ..

Any help will be greatly appreciated.

Best Regards, Mohammed Sadiq....

A: 

Blocks (closures) is a feature of C first introduced in LLVM Clang, and actually made popular in Mac OS X 10.6, and ported to iPhoneOS on 4.0. Therefore you should be able to find a lot of non-NDA information about blocks, e.g. an introduction by Apple in http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/Blocks/Articles/00_Introduction.html#//apple_ref/doc/uid/TP40007502-CH1-SW1.

Usually you declare the block as an anonymous function, like this:

 int x = 0;
 [foo … usingBlock:^(ALAssetsGroup* group, BOOL* stop) {
                       NSLog(@"%@", group);
                       ++ x;
                       if (x > 5)
                          *stop = YES;
                   } …];

Here the ^ introduces an inline block (anonymous function), and the rest is the definition of that function.

This function iterates over foo, prints the enumerated group to console, until the 5th item where the loop is broken.

KennyTM