swift - Lazy loading variable error -


i writing program involves core data. created class variable context , entity , have code written this:

class persistencymanager {      var context : nsmanagedobjectcontext{         let appdelegate = uiapplication.sharedapplication().delegate as! appdelegate         let localcontext = appdelegate.managedobjectcontext         return localcontext     }     var userentity : nsentitydescription {         let entity = nsentitydescription.entityforname(entitynames.user, inmanagedobjectcontext: context)         return entity!      }       struct entitynames {         private static let user = "user"         private static let category = "category"     } } 

everything far works fine, want "lazy"ly load userentity

like :

   lazy var userentity : nsentitydescription = {         let entity = nsentitydescription.entityforname(entitynames.user, inmanagedobjectcontext: context)         return entity!      }() 

but when do, error: "instance member 'context' cannot used on type 'persistency manager' "

what doing wrong? how can achieve goal?

thank you!

try let entity = nsentitydescription.entityforname(entitynames.user, inmanagedobjectcontext: self.context)

note i'm using self.context instead of context. builds me in playground.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -