iosobjective-cxcodeoutlet

Put underline before outlets In Xcode


Why I must put an underscore before IBOutlet names to use them? i.e. when I type this:

myLabel.text = @"Hello World";

Xcode says me

Put an underLine before outlet name

It means I must type this instead:

_myLabel.text = @"Hello World";

Why I must do that?

I use Xcode 6.3.2 And Yosemite 10.10.1


Solution

  • According to your property declaration, Xcode will automatically synthesize ivar with the same name and underscore prepending. There is simple no var with name you are using. So here is cases:

    1. Use it with underscore
    2. Use it with the self.myLabel
    3. Use @synthesize myLabel = someAnotherName; or simple @synthesize myLabel; to override that bahavior