Hi I'm here for advice to see whether what I'm doing is the best option is is fine for swift. I have a view controller that I present from viewcontroller1. In viewcontroller2 I have a textfield and when the text is full I save the text to my singleton and initiate an action in view controller 1 through a protocol to save that text to the database and update the uilabels in view controller 1 with those labels and then I dismiss view controller two. I initiate a function from view controller2 in view controller1 to save the data from the singleton to the database. Is this fine to do. If you have any questions feel free to ask.
class ViewController1: UIViewController, EditProtocol{
var label = UIlabel()
@IBAction func Editname(_ sender: Any) {
if let vc = storyboard.instantiateViewController(withIdentifier: "ViewController2Identifier") as? ViewController2{
vc.controller = self
vc.modalPresentationStyle = .custom
vc.modalTransitionStyle = .crossDissolve
vc.setViewControllers([ProductInformation], animated: true)
self.present(vc, animated:true, completion: nil)
}
}
func SaveName() {
label.text = singleton.shared.text
}
protocol EditProtocol {
func SaveName()
}
class ViewController2: UIViewController{
var controller: EditProtocol?
@IBOutlet weak var Name: UITextField!
@IBAction func Back(_ sender: AnyObject) {
singleton.shared.text = Name.text
controller?. SaveName()
self.dismiss(animated: true, completion: nil)
}
}