How do you reference an Objective C AppDelegate from a Swift Class? -


i have objective c project , trying call appdelegate swift view controller. code not working:

let appdelegate =         uiapplication.sharedapplication().delegate as! appdelegate  let managedcontext = appdelegate.managedobjectcontext 

have added brining header project?

on top of that, if do, make sure import "appdelegate.h" bridging header.

the in swift class should able call with:

guard let appdele = uiapplication.sharedapplication().delegate as? appdelegate else {     fatalerror("unable reference app delegate, check settings , riding header") } let managedcontext = appdele.managedobjectcontext 

Comments