3
votes

I saw several people on SO have been using this code successfully. But I got the incompatible block pointer error:

Incompatible block pointer types initializing

void(^)(struct ALAssetsGroup *, BOOL *)

with an expression of type

void(^)(ALAsset *, NSUInteger, BOOL *)

Any hints? (EDIT with complete code)

    ALAssetsLibrary *library =[[ALAssetsLibrary alloc]init];
    void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop){
    if(result != NULL) {
                NSLog(@"See Asset: %@", result);

            }
        };

    void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
            if(group != nil) {NSLog(@"dont See Asset: ");
                [group enumerateAssetsUsingBlock:assetEnumerator];
            }
        };

    [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                               usingBlock:assetGroupEnumerator
                             failureBlock: ^(NSError *error) {
                                 NSLog(@"Failure");
                             }];

enter image description here

2
Post more of your code -- the snippets you have there seem fine. - Daniel Dickison
If you could tell us what line of code the compiler is barking at, it would really help us help you. - Codo
Added image that shows error messages. - user523234

2 Answers

9
votes

OK, newbie at blocks... but I found another example of an asset group enumerator block on here, and it didn't have struct in the declaration. I tried removing it from the code above, and it still works fine and doesn't have the error message. Hopefully someone who understands struct better can explain?

try changing this line:

void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) 
            = ^(ALAssetsGroup *group, BOOL *stop)

to this:

void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) 
            = ^(ALAssetsGroup *group, BOOL *stop)

I think the bottom line is that the ALAssetsLibrary enumerateGroupsWithTypes: usingBlock: expects a block looking like (ALAssetsGroup *, BOOL *) not (struct ALAssetsGroup *, BOOL *).

3
votes

The difference between the expected and the actual type is just the work struct, i.e. struct ALAsset* vs. ALAsset*. (In your textual description it looks like a mismatch between ALAsset and ALAssetGroups, but I think you made a mistake in copying the error message.)

I don't quite understand where these differences come from (possibly due to the use of C++ somewhere?).

Anyway, the best solution is to use the type definition ALAssetsGroupEnumerationResultsBlock or ALAssetsLibraryGroupsEnumerationResultsBlock respectively, e.g.:

ALAssetsGroupEnumerationResultsBlock assetEnumerator = ^(ALAsset *result, NSUInteger index, BOOL *stop){
    if (result != NULL) {
            NSLog(@"See Asset: %@", result);
        }
    };