ho un riferimento alla mia app delegatoclassName.type non ha un membro chiamato 'appDel'
let appDel: AppDelegate = (UIApplication.sharedApplication().delegate) as AppDelegate
Questo funziona bene, ma questa riga di codice che segue riporta un errore:
let context: NSManagedObjectContext = appDel.managedObjectContext
mi dà il seguente errore:
'vctGebruikers.Type' does not have a member named 'appDel'
li ho dichiarato proprio sotto la mia classe in questo modo:
class vctGebruikers: UIViewController, UITableViewDelegate, UITableViewDataSource {
let appDel: AppDelegate = (UIApplication.sharedApplication().delegate) as AppDelegate
let context: NSManagedObjectContext = appDel.managedObjectContext
}
La cosa strana è quando si incolla il codice in viewDidLoad
o in una funzione il codice funziona correttamente. E non riesco a capire quale sia il problema. Come posso risolvere questo errore?
EDIT: ho anche bisogno di acces contesto qui:
let results: NSArray = context.executeFetchRequest(request, error: nil)
Questo è quello che ho ottenuto grazie al lavoro per @Antonio, ma ora non è im grado di acces contesto e appDel
init(coder aDecoder: NSCoder!) {
let appDelegate = (UIApplication.sharedApplication().delegate) as AppDelegate
self.appDel = appDelegate
self.context = appDelegate.managedObjectContext
super.init(coder: aDecoder)
}
make 'appDel' un calcolato' GET' proprietà - ha più senso – kambala