开发者

Alternate to assigning return values

I am new to Objective C. On one of the developers documentation, I found the following statemenet.

The following statement invokes the lockFocusIfCanDraw me开发者_开发百科thod and assigns the return value to flag. It does not generate a compiler warning unless there is a mismatch between the type for flag and the method’s return type. Nonetheless, this pattern is strongly discouraged.

flag = aView.lockFocusIfCanDraw;

In addition to the one above, I can think of many situations of this kind. For instance I might want to capture the display text from a box and assign it to a local string etc.

I am just wondering, if the above statement is discouraged, what is the recommended way of handling such situation?


The dot syntax for calling methods should only be used for properties (i.e. when calling accessors). Since lockFocusIfCanDraw is not an accessor method, you should use the regular square brackets syntax, i.e. flag = [aView lockFocusIfCanDraw]; instead.


flag = [aView lockFocusIfCanDraw];

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜