uti0mnia
uti0mnia

Reputation: 394

AppDelegate type var is not member unless in func (see pictures)

I'm just starting Swift, have some Objective-C background... Anyways, why is it that when I do:
error

I get an error, but when I put it in a func like:

good

There isn't an error?

Also, can someone please correct my terms? is appDel a reference or a variable? Thanks in advanced - please edit or tell me what's wrong with my question :)

Upvotes: 1

Views: 157

Answers (1)

linimin
linimin

Reputation: 6377

You can't access self when setting the default value.

Mark it with lazy attribute can do the trick:

lazy var context: NSManagedObjectContext = self.appDel.managedObjectContext

Upvotes: 2

Related Questions