0

我正在处理一些照片资产,我正在尝试浏览我的相机胶卷并打印出每张照片中的所有资产。我知道它需要是一个 for 循环,但只是不完全确定如何编写它

guard let selectedIndexPath = collectionView.indexPathsForSelectedItems?.first else { return nil }

let sectionType = sections[selectedIndexPath.section]
let item = selectedIndexPath.item
let assets: PHFetchResult<PHAsset>
let title: String

switch sectionType {
case .all:
  assets = allPhotos
  title = AlbumCollectionSectionType.all.description

case .smartAlbums, .userCollections:
  let album =
    sectionType == .smartAlbums ? smartAlbums[item] : userCollections[item]
  assets = PHAsset.fetchAssets(in: album, options: nil)
  title = album.localizedTitle ?? ""
}
print("\(assets)")
print("\(assets.object(at: 0))")
return PhotosCollectionViewController(assets: assets, title: title, coder: coder)'
4

1 回答 1

0

您可以使用.enumerateObjectsonassets循环它们:

assets.enumerateObjects { (asset, count, stop) in
    //asset is the PHAsset
}
于 2021-06-17T17:16:07.663 回答