I have a "profile header" view, with 2 different UIImageView, and 2 UIButton - one button for each image view. And I'm using a protocol to delegate the Target/selector of each button to my controller.
On my controller:
// my image picker
private let profileImagePicker = UIImagePickerController()
// Set's the profile image and Cover pic
private var selectedProfilePic: UIImage? {
didSet {
headerView.profileImageView.image = selectedProfilePic
}
}
private var selectedCoverPic: UIImage? {
didSet {
headerView.profileCover.image = selectedCoverPic
}
}
On this controller, I also have 2 functions for each button present on my view. One for my profile pic button, another to Cover pic button. Both presents the image Picker
func ChangeCoverPhoto(){
present(profileImagePicker, animated: true, completion: nil)
}
func ChangeProfilePhoto(){
present(profileImagePicker, animated: true, completion: nil)
}
Then I have the extension for UIImagePickerControllerDelegate
func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let image = info[.editedImage] as? UIImage else { return }
// ** here my Problem begin **
selectedProfilePic = image
}
How can I Set the selected image from the imagepicker on the selectedProfilePic OR selectedCoverPic based on the corresponding function trigged by the buttons via protocol?