Code Block Hi, any idea why I am getting an error in line "21" ? |
Thank you. |
Code Block |
1. final func chooseLastImage(_ sender: Any) { |
2. |
3. let imgManager = PHImageManager.default() |
4. |
5. let fetchOptions = PHFetchOptions() |
6. |
7. let requestOptions = PHImageRequestOptions() |
8. |
9. requestOptions.version = .original |
10. |
11. requestOptions.isSynchronous = false |
12. |
13. requestOptions.isNetworkAccessAllowed = false |
14. |
15. let targetSize: CGSize? = CGSize(width: photoImageView.bounds.width, height: photoImageView.bounds.height) |
16. |
17. fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: true)] |
18. |
19. let fetchResult: PHFetchResult<PHAsset> = PHAsset.fetchAssets(with: .image, options: fetchOptions) |
20. |
21. imgManager.requestImage(for: fetchResult.lastObject!, targetSize: targetSize!, contentMode: .aspectFit, options: requestOptions) { (result, info) in |
22. |
23. guard let result = result else { return } |
24. |
25. DispatchQueue.main.async(execute: { |
26. |
27. self.pickedImage = result |
28. |
29. self.photoImageView.image = self.pickedImage |
30. |
31. }) |
32. |
33. } |
34. |
35. } |
36. |
37. extension PhotoViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { |
38. |
39. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { |
40. |
41. if let editedImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage { |
42. |
43. photoImageView.image = updatedImage |
44. |
45. } else if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage { |
46. |
47. pickedImage = image |
48. |
49. photoImageView.image = pickedImage |
50. |
51. } |
52. |
53. dismiss(animated: true, completion: nil) |
54. |
55. } |
56. |
57. func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { |
58. |
59. dismiss(animated: true, completion: nil) |
60. |
61. } |
62. |
63. } |
|