Friday 15 July 2011

ios - Share Core Data database between app and today extension in Swift -



ios - Share Core Data database between app and today extension in Swift -

i have database widget has read data. i've set membership targets related files both app , widget. there problem though.

i have helper class in main app gets appdelegate context whenever operations on database. code looks follows:

class func getentityandcontext(name:string) -> (entity:nsentitydescription, context: nsmanagedobjectcontext){ var appdel:appdelegate = uiapplication.sharedapplication().delegate appdelegate allow context:nsmanagedobjectcontext = appdel.managedobjectcontext! allow entity:nsentitydescription = nsentitydescription.entityforname(name, inmanagedobjectcontext: context)! homecoming (entity, context) }

this method helps me in cases these:

class func getall() -> array<city>{ allow (_, context) = nsmanagedobjectwrapper.getentityandcontext("city") allow req = nsfetchrequest(entityname: "city") req.sortdescriptors = [nssortdescriptor(key: "order", ascending: true)] allow citieslist:array<city> = context.executefetchrequest(req, error: nil)! array<city> homecoming citieslist }

after added target membership widget, error: use of undeclared type 'appdelegate'. makes sense, have no thought how prepare it. can please help me?

ps: noticed error too: use of unresolved identifier 'nsfetchrequest'. doing wrong? certainly can't way it...

i found reply here: https://github.com/pjchavarria/swift-widget

this git project shows how utilize core info in widget.

ios widget

No comments:

Post a Comment