I have these codes when I use storyboard:
override func prepare (for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == ProfilePhotoViewController.identifier {
guard let username = usernameTextField.text, let email = emailTextField.text, let password = passwordTextField.text else { return }
let profilePhotoVC = segue.destination as! ProfilePhotoViewController
profilePhotoVC.email = email
profilePhotoVC.username = username
profilePhotoVC.password = password
}
}
How do I write these code if I don't use storyboard and write them programmatically in order to pass the info from current controller to ProfilePhotoViewController?
EDIT: After doing research I understand that doing this programmatically is through delegate. However, I don't know how I can complete the code:
Need to pass username, email and password from SignUpController ---> profilePhotoViewController
in SignUpController:
protocol SignUpControllerDelegate {
func handleSignUp(//what should I write here?)
}
var delegate: SignUpControllerDelegate?
@objc func handleSignUp() {
//...other code..//
delegate?.handleSignUp(//??)
}
In ProfileViewController:
what should I write to receive the username, email and password info from SignUpController?
Try like this
guard let username = usernameTextField.text, let email = emailTextField.text, let password = passwordTextField.text else { return }
let profileVC = ProfilePhotoViewController()
profileVC.email = email