Request data from CoreData in today's extension

advertisements

i have an app with ios 8, swift and CoreData. all works fine :)

now i would like to add an today extion - this is my first time to work with today extions. i very proud to say, that i already can set in my app an NSUserdafault value and show it on my today extension :)

but now i would like to go a step forward. in my app i have a CoreData Entiny LM_ITEMS with an Attribute "Hersteller"

how can i list up all data of LM_ITEMS in my today extension? Thank you :)

in my app i do it like this way:

let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
var LM = [LM_ITEMS]()

func DatenAbrufen() {
    let fetchRequest = NSFetchRequest(entityName: "LM_ITEMS")
    if let fetchResults = managedObjectContext!.executeFetchRequest(fetchRequest, error: nil) as? [LM_ITEMS] {
        LM = fetchResults
    }
}

But this doesnt work in today extension ...


You should better create a core data stack singleton object and include it in both targets, your app's target and extension target.