ios - UIApplication has no member shared -


im'm building app ios system swift language. have add project, core data.

i have created 'coredatacontroller'

this code of it:

import foundation import coredata import uikit  class coredatacontroller {      static let shared = coredatacontroller()      private var context: nsmanagedobjectcontext      private init() {         let application = uiapplication.shared.delegate as! appdelegate         self.context = application.persistentcontainer.viewcontext     }  } 

at line uiapplication.shared.delegate ..... have error

type 'uiapplication' has no member shared

this appdelegade file

import uikit import coredata  @uiapplicationmain class appdelegate: uiresponder, uiapplicationdelegate {      var window: uiwindow?       func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool {         // override point customization after application launch.         return true     }      func applicationwillresignactive(application: uiapplication) {         // sent when application move active inactive state. can occur types of temporary interruptions (such incoming phone call or sms message) or when user quits application , begins transition background state.         // use method pause ongoing tasks, disable timers, , throttle down opengl es frame rates. games should use method pause game.     }      func applicationdidenterbackground(application: uiapplication) {         // use method release shared resources, save user data, invalidate timers, , store enough application state information restore application current state in case terminated later.         // if application supports background execution, method called instead of applicationwillterminate: when user quits.     }      func applicationwillenterforeground(application: uiapplication) {         // called part of transition background inactive state; here can undo many of changes made on entering background.     }      func applicationdidbecomeactive(application: uiapplication) {         // restart tasks paused (or not yet started) while application inactive. if application in background, optionally refresh user interface.     }      func applicationwillterminate(application: uiapplication) {         // called when application terminate. save data if appropriate. see applicationdidenterbackground:.         self.savecontext()     }      lazy var persistentcontainer: nspersistentcontainer = {         /*          persistent container application. implementation          creates , returns container, having loaded store          application it. property optional since there legitimate          error conditions cause creation of store fail.          */         let container = nspersistentcontainer(name: "arduinohomekit")         container.loadpersistentstores(completionhandler: { (storedescription, error) in             if let error = error nserror? {                 // replace implementation code handle error appropriately.                 // fatalerror() causes application generate crash log , terminate. should not use function in shipping application, although may useful during development.                  /*                  typical reasons error here include:                  * parent directory not exist, cannot created, or disallows writing.                  * persistent store not accessible, due permissions or data protection when device locked.                  * device out of space.                  * store not migrated current model version.                  check error message determine actual problem was.                  */                 fatalerror("unresolved error \(error), \(error.userinfo)")             }         })         return container     }()  } 

i have jump information of appdelegate file?

use xcode 7.3.1 swift 2.2

let appvar = uiapplication.sharedapplication().delegate as! appdelegate 

and swift 3.x (xcode 8.0 , newer)

let appvar = uiapplication.shared.delegate as! appdelegate 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -