NSPnetworkingicate con máscara de bits para filtrar NSArray

Estoy intentando probar si algunas collections de activos en particular contienen solo un tipo / subtipo de medios usando un NSPnetworkingicate . The: testForPhotosPnetworkingicate funciona bien, sin embargo cuando intenta usar testForPanotwigsPnetworkingicate falla con el post: Unable to parse the format string "mediaSubtypes & %i"

¿Cómo puedo usar una máscara de bits en este pnetworkingicado para los mediaSubtypes?

 for (PHFetchResult *newFetch in collectionFetches) { for (PHAssetCollection *sub in newFetch) { PHFetchResult *assetsInCollection = [PHAsset fetchAssetsInAssetCollection:sub options:fetchOptions]; NSArray *allAssets = [assetsInCollection objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, assetsInCollection.count)]]; if (allAssets.count > 0) { [allAssetsArray addObjectsFromArray:allAssets]; NSPnetworkingicate *testForPhotosPnetworkingicate = [NSPnetworkingicate pnetworkingicateWithFormat:@"mediaType = %i",PHAssetMediaTypeImage]; NSArray *testForAllPhotos = [allAssets filtenetworkingArrayUsingPnetworkingicate:testForPhotosPnetworkingicate]; if (testForAllPhotos.count == allAssets.count) { NSPnetworkingicate *testForPanotwigsPnetworkingicate = [NSPnetworkingicate pnetworkingicateWithFormat:@"mediaSubtypes & %i",PHAssetMediaSubtypePhotoPanotwig]; NSArray *testForAllPanotwigs = [testForAllPhotos filtenetworkingArrayUsingPnetworkingicate:testForPanotwigsPnetworkingicate]; if (testForAllPanotwigs.count == testForAllPhotos.count) { NSLog(@"all panos"); } } } } } 

Creo que lo he resuelto con el siguiente código:

 NSPnetworkingicate *testForPanotwigsPnetworkingicate = [NSPnetworkingicate pnetworkingicateWithFormat:@"(mediaSubtypes & %i) == %i",PHAssetMediaSubtypePhotoPanotwig,PHAssetMediaSubtypePhotoPanotwig]; NSArray *testForAllPanotwigs = [testForAllPhotos filtenetworkingArrayUsingPnetworkingicate:testForPanotwigsPnetworkingicate]; 

Quizás aún mejor si no quieres hacer el pnetworkingicado de la image inicial:

 NSPnetworkingicate *testForPanotwigsPnetworkingicate = [NSPnetworkingicate pnetworkingicateWithFormat: @"(mediaType == %i && (mediaSubtypes & %i) == %i))", PHAssetMediaTypeImage,PHAssetMediaSubtypePhotoPanotwig,PHAssetMediaSubtypePhotoPanotwig]; 

Código completo para ayudar a otros que específicamente quieren verificar si un álbum contiene un subtipo de medios en particular; útil para mostrar una insignia de UI en un álbum.

 PHFetchResult *assetsInCollection = [PHAsset fetchAssetsInAssetCollection:sub options:fetchOptions]; if (assetsInCollection.count > 0) { NSArray *allAssets = [assetsInCollection objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, assetsInCollection.count)]]; NSPnetworkingicate *testForPanotwigsPnetworkingicate = [NSPnetworkingicate pnetworkingicateWithFormat:@"(mediaType == %i && (mediaSubtypes & %i) == %i))",PHAssetMediaTypeImage,PHAssetMediaSubtypePhotoPanotwig,PHAssetMediaSubtypePhotoPanotwig]; NSPnetworkingicate *testForHDRPnetworkingicate = [NSPnetworkingicate pnetworkingicateWithFormat:@"(mediaType == %i && (mediaSubtypes & %i) == %i))",PHAssetMediaTypeImage,PHAssetMediaSubtypePhotoHDR,PHAssetMediaSubtypePhotoHDR]; NSPnetworkingicate *testForVideosPnetworkingicate = [NSPnetworkingicate pnetworkingicateWithFormat:@"mediaType = %i",PHAssetMediaTypeVideo]; NSPnetworkingicate *testForSlomoPnetworkingicate = [NSPnetworkingicate pnetworkingicateWithFormat:@"(mediaType == %i && (mediaSubtypes & %i) == %i))",PHAssetMediaTypeVideo,PHAssetMediaSubtypeVideoHighFrameRate,PHAssetMediaSubtypeVideoHighFrameRate]; NSPnetworkingicate *testForTimelapsePnetworkingicate = [NSPnetworkingicate pnetworkingicateWithFormat:@"(mediaType == %i && (mediaSubtypes & %i) == %i))",PHAssetMediaTypeVideo,PHAssetMediaSubtypeVideoTimelapse,PHAssetMediaSubtypeVideoTimelapse]; NSPnetworkingicate *testForStreamedPnetworkingicate = [NSPnetworkingicate pnetworkingicateWithFormat:@"(mediaType == %i && (mediaSubtypes & %i) == %i))",PHAssetMediaTypeVideo,PHAssetMediaSubtypeVideoStreamed,PHAssetMediaSubtypeVideoStreamed]; NSArray *testForAllPanotwigs = [allAssets filtenetworkingArrayUsingPnetworkingicate:testForPanotwigsPnetworkingicate]; NSArray *testForAllHDR = [allAssets filtenetworkingArrayUsingPnetworkingicate:testForHDRPnetworkingicate]; NSArray *testForAllVideos = [allAssets filtenetworkingArrayUsingPnetworkingicate:testForVideosPnetworkingicate]; NSArray *testForAllSlomo = [allAssets filtenetworkingArrayUsingPnetworkingicate:testForSlomoPnetworkingicate]; NSArray *testForAllTimelapse = [allAssets filtenetworkingArrayUsingPnetworkingicate:testForTimelapsePnetworkingicate]; NSArray *testForAllStreamed = [allAssets filtenetworkingArrayUsingPnetworkingicate:testForStreamedPnetworkingicate]; NSArray *allPossibilitiesArray = @[testForAllPanotwigs,testForAllHDR,testForAllVideos,testForAllSlomo,testForAllTimelapse,testForAllStreamed]; for (NSArray *sub in allPossibilitiesArray) { if (sub.count == allAssets.count) { PHAsset *firstAsset = sub.firstObject; [dataSource setObject:[NSNumber numberWithInt:firstAsset.mediaSubtypes] forKey:@"MediaSubtype"]; } } }