ios - How to use a variable in other class that is defined in AppDelegate -


i have variable var window: uiwindow? in appdelegate.swift file inside class appdelegate want use in other class xyz.swift file inside class xyz explained in here get current view controller app delegate (modal possible) getting error @ first line appreciated. here code xyz.swift

func currentview() -> uiview   {      let navigationcontroller = window?.rootviewcontroller as? uinavigationcontroller // use of unresolved identifier 'window'      if let activecontroller = navigationcontroller!.visibleviewcontroller {      if activecontroller.iskindofclass( myviewcontroller )  {        println("i have found controller!")           }       }   } 

even if use let navigationcontroller = appdelegate.window?.rootviewcontroller as? uinavigationcontroller error 'appdelegate.type' not have member named 'window'

you may have follows:

    var appdelegate = uiapplication.sharedapplication().delegate appdelegate     let navigationcontroller = appdelegate.window?.... 

as @dave durbin has pointed out trying use variable defined in 1 class class without reference of defining class.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -