ALAssetsLibrary.enumerateGroupsWithTypes first parameter in Swift

I am trying to use the enumerateGroupsWithTypes method of the ALAssetsLibrary class, but I am getting an error with the first parameter.

Method prototype:

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

As I call this method:

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

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

Other tests:

Based on what I found on the Internet and my own tests, I also tried

Test 1

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

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

Test 2

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

And the result is an EXC_BAD_ACCESS runtime EXC_BAD_ACCESS and EXC_BAD_ACCESS failure.

+6
source share
2 answers

It seems like the right way is to use the ALAssetsGroupType initializer to create a new ALAssetsGroupType . The following should work:

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

This is like compiling:

Although, it was not tested, since I do not know for sure that it returns using allZeros .

It can return 0x00000 , unlike what you need, it is 0xFFFFFF .

Still may be a good reference for people in the future.

 let assetLib = ALAssetsLibrary() assetLib.enumerateGroupsWithTypes(ALAssetsGroupType.allZeros, usingBlock: { (results, stop) in println(results) }, failureBlock: { (fail) in println(fail) }) 

EDIT:

Well, what happens if you do the following?

 assetLib.enumerateGroupsWithTypes(0xFFFFFFFF, usingBlock: ...) 

I get the following:

 (ALAssetsGroup - Name:Instagram, Type:Album, Assets count:46, ) (ALAssetsGroup - Name:Snapchat, Type:Album, Assets count:0, ) (ALAssetsGroup - Name:Camera Roll, Type:Saved Photos, Assets count:681, ) (nil, ) 

Probably a bug like Jack Wu mentioned where they probably used enum , not NS_ENUM , and the translator broke down.

This may currently be a workaround.

Asset types

Constants for determining asset types.

 enum { ALAssetsGroupLibrary = (1 << 0), ALAssetsGroupAlbum = (1 << 1), ALAssetsGroupEvent = (1 << 2), ALAssetsGroupFaces = (1 << 3), ALAssetsGroupSavedPhotos = (1 << 4), ALAssetsGroupPhotoStream = (1 << 5), ALAssetsGroupAll = 0xFFFFFFFF, }; 
-1
source

Source: https://habr.com/ru/post/971975/


All Articles