开发者

Syntax question on accessing properties of objects stored in a NSMutableArray

开发者 https://www.devze.com 2022-12-19 16:52 出处:网络
Could someone explain why the second syntax of the same expression does not work?If you need some background, manyViews is a pointer to an NSMutableArray loaded with UIView objects.

Could someone explain why the second syntax of the same expression does not work? If you need some background, manyViews is a pointer to an NSMutableArray loaded with UIView objects.

[[manyViews objectAtIndex:0] setFrame:CGRectMake(30,30,100,20)];  // wor开发者_运维问答ks as intended

[manyViews objectAtIndex:0].frame = CGRectMake(30,30,100,20);     // compiler does not recognize the "frame" member


Current limitation of the compiler (both gcc and Clang). Dot notation is hopelessly overloaded, and the compiler thinks you're trying to assign a field in a struct. The id isn't a struct, so it gives an error. I use it myself, but I still say dot notation was definitely the worst addition in ObjC2. It creates a lot of confusion for programmers, and as we see here, often creates confusion for the compiler.

Later versions of gcc or clang may work out a way to parse this correctly.

0

精彩评论

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

关注公众号