I can't import photos in collection view

Viewed 27

Need Help


Hello Guys i am trying to fetch gallary photos to uicollection view but it's show me fatelerror if any one have a solution so please help me

i mark the fatel error plese show it end help me erlier its a very important project for me thank you again advance

Hear is the code

   class ADDVC: UIViewController {

//MARK:- Outlets
    @IBOutlet weak var IMG_SelectedImageView: UIImageView!
    
    @IBOutlet weak var cameraRollCollectionView: UICollectionView!

    
//MARK:- variables
    
    var assetCollection: PHAssetCollection!
    var photosAsset: PHFetchResult<AnyObject>!
    var assetThumbnailSize: CGSize!

    
    //MARK:- Controller Life Cycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let fetchOptions = PHFetchOptions()

        let collection:PHFetchResult = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: .some(fetchOptions))

          if let first_Obj:AnyObject = collection.firstObject{
              //found the album
            self.assetCollection = (first_Obj as! PHAssetCollection)
          }
//MARK:- Select Photo
        
        tabBarItem.image = UIImage(contentsOfFile: "Plus")
//MARK:- Select Video
    }
    override func viewWillAppear(_ animated: Bool) {
        // Get size of the collectionView cell for thumbnail image
        if let layout = self.cameraRollCollectionView!.collectionViewLayout as? UICollectionViewFlowLayout{
            let cellSize = layout.itemSize

            self.assetThumbnailSize = CGSize(width: cellSize.width, height: cellSize.height)
        }

        //fetch the photos from collection
        self.photosAsset = (PHAsset.fetchAssets(in: self.assetCollection, options: nil) as AnyObject?) as! PHFetchResult<AnyObject>?   //HEAR I AM GETTING THE FATEL ERROR 


        self.cameraRollCollectionView!.reloadData()

    }
0 Answers
Related