开发者

Is it valid to ignore an return value of an method in objective-c?

开发者 https://www.devze.com 2022-12-22 17:18 出处:网络
For example, when I call a method that returns an value, but I\'m not interested in this at all, can I safely ignore that?

For example, when I call a method that returns an value, but I'm not interested in this at all, can I safely ignore that?

Example, instead of:

CGSize size = [str sizeWithFont:myFont minFontSize:19.0f actualFontSize:&actualFontSize forWidth:150.0f lineBreakMode:UILineBreakModeClip];

...do this:

[str s开发者_开发百科izeWithFont:myFont minFontSize:19.0f actualFontSize:&actualFontSize forWidth:150.0f lineBreakMode:UILineBreakModeClip];

I don't need the CGSize size but only actualFontSize, which is passed in by reference. Now the problem is that XCode gives me a warning if I don't read size. I don't want to surpress those warnings, and at the same time I don't want them at all.

So I wonder if it's okay if I just don't assign the return value to anything?


I didn't think Xcode worried about it at all. No, it's not going to do anything bad.

If you want to cleanly shut up the warning, cast the return value to void:

(void)[str sizeWithFont:myFont minFontSize:19.0f actualFontSize:&actualFontSize forWidth:150.0f lineBreakMode:UILineBreakModeClip];
0

精彩评论

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