How to assign boolean value to appdelegate method from view controller

Viewed 377

I am new to IOS and swift. Does anyone know how to assign value to boolean appdelegate method? I want to set shouldAllowExtensionPointIdentifier in viewcontroller but i didn't find any solution. Thank you

    //
//  AppDelegate.swift
//  TestKeyboard
//
//  Created by Mol Monyneath on 11/1/17.

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

   public var Alow : Bool?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch     
        return true
    }
    func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplicationExtensionPointIdentifier) -> Bool {

          print("\(extensionPointIdentifier.rawValue) allow =  \(Alow)")
            return Alow!

   }
}

Here is Main view controller: I couldn't block that app . please help

import UIKit

class ViewController: UIViewController,UITextFieldDelegate {
    @IBOutlet weak var normaltextView: UITextField!
    @IBOutlet weak var txtView: UITextField!
    var appDelegate = UIApplication.shared.delegate as! AppDelegate
    override func viewDidLoad() {
        super.viewDidLoad()

        normaltextView.delegate = self
        txtView.delegate = self 
    }

    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {   
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        if textField.keyboardType == UIKeyboardType.numberPad{
           // textField.inputView = nil
            txtView.inputView = nil
            appDelegate.Alow = false
            txtView.reloadInputViews()

            print("false")

        }else{
            print("should Press")
            print("True")
          //  textField.inputView = nil
            appDelegate.Alow = true
            txtView.reloadInputViews()
            normaltextView.reloadInputViews()
        }  
        return true
    }        
}

thank

0 Answers
Related