开发者

iPhone - ampersand, what ampersand?

I see this line on one of Apple samples...

if (&ADBannerContentSizeIdentifierPortrait != nil)

what is exactly this ampersan开发者_StackOverflow中文版d doing that?

thanks


The ampersand in C and languages that "derive" from it (like C++ and Objective-C) returns the address of a variable (instead of the content).

In this case, what's happening is this: the variable ADBannerContentSizeIdentifierPortrait is a weakly linked variable. This means, at runtime it may be missing (this is the case in older OS versions). Now, if the variable does exist the ampersand returns an address. If the OS does not yet have this variable, the ampersand returns nil.

So in short: the expression checks whether the OS is already providing the variable ADBannerContentSizeIdentifierPortrait. According do the documentation this variable exists since iOS 4.2, so the body of the if expression is only executed on iOS >= 4.2.


The ampersand depicts a reference to the data. The ADBannerContentSizeIdentifierPortrait is a simple enumerated value, and therefore cannot be nil itself, but it's reference can be. Please add more code if you require a more thorough answer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜