Answers for "SwifUI call the function in the cordinator"

0

SwifUI call the function in the cordinator

import Foundation
import SwiftUI
import UIKit

struct AnotherControllerView : UIViewControllerRepresentable {

    typealias UIViewControllerType = AnotherController

    func makeCoordinator() -> AnotherControllerView.Coordinator {
        Coordinator(self)
    }

    func makeUIViewController(context: UIViewControllerRepresentableContext<AnotherControllerView>) -> AnotherController {

        return AnotherController()
    }

    func updateUIViewController(_ uiViewController: AnotherController, context: UIViewControllerRepresentableContext<AnotherControllerView>) {

    }


    class Coordinator : NSObject {
        var parent : AnotherControllerView
        init(_ viewController : AnotherControllerView){
            self.parent = viewController
        }
    }
}

class AnotherController : UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.blue
    }

    func savePhoto(){

        let alert = UIAlertController(title: "Save Photo to Camera Roll", message: "Would you like to save your drawing to the camera roll?", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
        alert.addAction(UIAlertAction(title: "Save", style: .default, handler: someHandler))
        self.present(alert, animated: true)
    }

    func someHandler(alert: UIAlertAction!) {
        print("Handler executed")
    }
}
Posted by: Guest on May-06-2021

Code answers related to "SwifUI call the function in the cordinator"

Browse Popular Code Answers by Language