Swift和iOS开发新手。有人能告诉我如何将两次调用的结果合并到PHAssetCollection.fetchAssetCollectionsWithType?具体而言,我试图在一个列表中包含标准相册和智能相册。将2个PHFetchResults组合在一起
感谢
Swift和iOS开发新手。有人能告诉我如何将两次调用的结果合并到PHAssetCollection.fetchAssetCollectionsWithType?具体而言,我试图在一个列表中包含标准相册和智能相册。将2个PHFetchResults组合在一起
感谢
我不知道这是否是一个最佳实践或什么,但我需要做一些事情今天这个样子,画面显示如下工作:
@property NSMutableArray<PHAssetCollection *> *collections;
...
/* Get albums of interest */
PHFetchResult *albums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype: ... options: ...];
/* Get smart albums of interest (in my case, the Camera Roll) */
PHFetchResult *cameraRoll = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options: ...];
/* Load albums into collections member */
for (NSUInteger i = 0; i < albums.count; ++i)
[self.collections addObject:[albums objectAtIndex:i]];
/* Load Camera Roll into collections member */
[self.collections addObject:[cameraRoll firstObject]];
只记得初始化您的收藏成员在添加对象之前。
您可以使用PHAsset的fetchAssetsWithLocalIdentifiers:options:api。 首先获得一张专辑:
PHFetchResult *album = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype: ... options: ...];
遍历它:
for (PHAsset *asset in album) {
[self.localIDList addObject:asset.localIdentifier];
}
使用此您需要的每个专辑。最后...
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:self.localIDList options:nil];
这会给我一个相册列表,或者相册中的资产列表吗?具体而言,我是在包含所有专辑的单个列表之后,而不是资产。 – Greg
相册中的资产列表。另外,如果你在多个相册中有相同的项目,那么它将丢弃重复的项目。 –
这个问题提到了Swift,而不是Objective-C。 – Moritz