Reputation: 11
I was working on my code when I got this error message at the part setProfilePicture : Cannot force unwrap value of non-optional type '(UIImagePickerController, [UIImagePickerController.InfoKey : UIImage]) -> ()' Could somebody tell me what happened and how to fix it ?
//Selecting image from Gallery
@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){
//let profileImage =
func profileImage(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : UIImage]){
}
setProfilePicture(imageView: self.imageSelector, imageToSet: profileImage)
self.dismiss(animated: true, completion: nil)
}
// Displaying Profile Picture on the Image View
internal func setProfilePicture(imageView: UIImageView, imageToSet: UIImage){
print("setProfilePicture called")
imageView.layer.cornerRadius = 40
imageView.layer.borderColor = UIColor.white.cgColor
imageView.layer.masksToBounds = true
imageView.image = imageToSet
}
}
Upvotes: 0
Views: 754
Reputation: 204
try this:
func imagePickerController(
_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]
)
{
if let image = info[.originalImage] as? UIImage {
setProfilePicture(imageView: self.imageSelector, imageToSet: image)
dismiss(animated: true, completion: nil)
}
}
Upvotes: 2
Reputation: 6037
You second argument to the func setProfilePicture(imageView:imageToSet: is profileImage! which is the forced unwrapping of the function you have declared above as not being optional.
Upvotes: 0