managedObjectContext not found

I declare the following:
struct ContentView: View {
@Environment(.managedObjectContext) var moc
and the .managedObjectContext does not go light green which normally happens if done properly.
consequently I get Value of type 'NSManagedObject' has no member 'lattitude'
Any help appreciated, thank you

@Environment(\.managedObjectContext) var managedObjectContext

I have no idea why but when I try to type \ in front of .managedObjectContext is does not show.

Environment.init(_:) takes keypath value.

keypath expression starts with \. So the full keypath looks like this:


which is then abbreviated like this (because of type inference):


Can't seem to type my layout so here's an image:

Drag over the whole text, then ctrl+i (not cmd+i).

This is what I think it should look:

How does it look after ctrl+i?

no change just indents the text

Does it compile? Some errors can interfere with indentation. (drag over all text and ctrl+i works for me though)

Thank you, It is not the indentation I am concerned with. The different color of .managedObjectContext , it should be green like in the second image but it is black as if not found. Sorry i didn't explain properly. thanks

Oh, I misread the replies.

The colouring takes time. Sometimes you may want to recompile the project. You may even need to close and reopen the IDE (if you DO need to do that, you should file a bug report).

Thanks Lantua... That worked.