In my project, I am capturing an image. But when it starts saving the image, app crashes with the error of -
\"unexpectedly found nil while unwrapping\"
The problem is that you have never given self.assetCollection
or self.photoAsset
any value, so they are nil. Thus, when you try to use them in your PHAssetCollectionChangeRequest initializer, you crash.
By the way, if all you want to do is save the image into the camera roll, you don't need all that code. The creation request alone is all you need.
Or, if you want to save the image into the camera roll and into an album, you don't need to call PHAssetCollectionChangeRequest(forAssetCollection:assets:)
to do it.
Finally, you really shouldn't have all that extra stuff in the change block. Just do the change and no more. The other stuff should be in the completion block.