照片框架在 Swift 中上升

Photos framework ascending in Swift

我的项目中有一个 collectionView 运行,它使用 Photos 框架获取 iPhone 照片库 successfully.I 我正在尝试从上次 photo.I 开始提升照片 collectionView使用以下代码....

  func getAllPhotosInfo() {
   photoAssets = []

    let options = PHFetchOptions()
    options.sortDescriptors = [
        NSSortDescriptor(key: "creationDate", ascending: false)
    ]

    let assets: PHFetchResult = PHAsset.fetchAssetsWithMediaType(.Image, options: options)
    assets.enumerateObjectsUsingBlock { (asset, index, stop) -> Void in
        self.photoAssets.append(asset as! PHAsset)
    }
    print(photoAssets)
}

//PHAsset转图片

import UIKit
import Photos

class CollectionViewCell: UICollectionViewCell {

var imageManager: PHImageManager?

@IBOutlet weak var photoImageView: UIImageView!

var imageAsset: PHAsset? {
    didSet {

            self.imageManager?.requestImageForAsset(self.imageAsset!, targetSize: CGSize(width: 320, height: 320), contentMode: .AspectFill, options: nil) { image, info in
            self.photoImageView.image = image
        }

    }
}

}

我正在研究 Photos 框架文档,我发现 answer.here 是工作代码....

var photoAssets = [PHAsset]()

func getAllPhotosInfo() {
   photoAssets = []

   let options = PHFetchOptions()
   options.sortDescriptors = [ NSSortDescriptor(key: "creationDate", ascending: false) ]
   options.predicate =  NSPredicate(format: "mediaType = %i", PHAssetMediaType.Image.rawValue)
   let assetCollections = PHAssetCollection.fetchAssetCollectionsWithType(PHAssetCollectionType.SmartAlbum, subtype: PHAssetCollectionSubtype.SmartAlbumUserLibrary, options: nil)

for i in 0 ..< assetCollections.count
{

        if let assetCollection = assetCollections[i] as? PHAssetCollection
        {
           images = PHAsset.fetchAssetsInAssetCollection(assetCollection, options: options)

             print(images.count)

            return
        }
   }
}