开发者

Why does dot notation work and not brackets?

开发者 https://www.devze.com 2023-01-04 04:57 出处:网络
So I\'m calling this: [leftSwi开发者_运维问答tch hidden:NO]; but the iPhone Simulator just crashes (no compiler errors) when I click on the Segmented Control that calls the IBAction that this code

So I'm calling this:

[leftSwi开发者_运维问答tch hidden:NO];

but the iPhone Simulator just crashes (no compiler errors) when I click on the Segmented Control that calls the IBAction that this code is from.

However, as soon as I change this to:

leftSwitch.hidden = NO;

it works...I made no other changes.


You want

[leftSwitch setHidden:NO];

Note the automatic change in name-- the method version gets the set prefix.


The default methods synthesized for properties are

[foo bar]

which is the getter, and

[foo setBar:other]

which is the setter.

But the property shorthand allows you to access these methods by using dot notation so it appears that you are accessing like any other ivar, but you are really using these synthesized properties in the background. in the property declaration, you can change the default names, but it is best to leave it based on the normal Objective C conventions.

0

精彩评论

暂无评论...
验证码 换一张
取 消