Question

Hi I am calling ALAssetsLibrary's

-enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:block failureBlock:failure;

then inside the enumeration block i want to compare the type of group returned and add it to the relevant array. I have tried

^( ALAssetsGroup *group, BOOL *stop )
{
    NSLog(@"Group %@", group );
    ALAssetGroupType assetType = (ALAssetGroupType)[group valueForProperty:ALAssetsGroupPropertyType];
    NSLog( @"Asset type %@", assetType );
    switch( assetType )
    {
        case ALAssetsGroupAplbum :
        NSLog( @"Found ALBUM" );
        [albums addObject:group];
        break;
    }
}

The Initial log traces out "Group ALAssetsGroup - Name:Photo Library, Type:Album, Assets count:177"

The next log is "Asset type 2"

but the third log never get's called.

Any ideas what i am doing wrong?

Was it helpful?

Solution

valueForProperty: returns an object. In the case of ALAssetsGroupPropertyType it returns an ALAssetGroupType constant wrapped in an NSNumber. (See docs here.)

So by casting to ALAssetGroupType you're using the object's memory address as your switch value. You need to get the underlying integer value of the NSNumber using intValue:

ALAssetGroupType assetType = 
 [[group valueForProperty:ALAssetsGroupPropertyType] intValue];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top