Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ALAssetsLibrary.enumerateGroupsWithTypes first parameter in Swift

I try to use the enumerateGroupsWithTypes method of the ALAssetsLibrary class but I get an error with the first parameter.

The method's prototype :

func enumerateGroupsWithTypes(types: ALAssetsGroupType,
    usingBlock enumerationBlock: ALAssetsLibraryGroupsEnumerationResultsBlock!,
    failureBlock: ALAssetsLibraryAccessFailureBlock!)

How I call this method :

assetLib.enumerateGroupsWithTypes(ALAssetsGroupAll, usingBlock: success, failureBlock: fail)

but I get a compile error 'CUnsignedInt' is not convertible to 'ALAssetsGroupType'

Other tests :

Based on what I've found on internet and my own tests, I've also tried

Test 1

assetLib.enumerateGroupsWithTypes(ALAssetsGroupAll as ALAssetsGroupType, usingBlock: success, failureBlock: fail)

And the result is a compile error Cannot convert the expression's type 'Void' to type 'ALAssetsGroupType'

Test 2

assetLib.enumerateGroupsWithTypes(ALAssetsGroupType(ALAssetsGroupAll), usingBlock: success, failureBlock: fail)

And the result is a runtime error EXC_BAD_ACCESS and an XCode crash.

like image 839
Morniak Avatar asked Jul 09 '14 13:07

Morniak


1 Answers

Looks like the correct way is to use ALAssetsGroupType's initializer to create a new ALAssetsGroupType. The following should work:

assetLib.enumerateGroupsWithTypes(ALAssetsGroupType(ALAssetsGroupAll), usingBlock: success, failureBlock: fail)
like image 156
Mike Akers Avatar answered Sep 28 '22 07:09

Mike Akers