XCode 4 if(self = [super init])问题 [英] XCode 4 if (self = [super init]) issue
问题描述
我最近(例如,现在)已升级到XCode 4,并且总体上我喜欢它,但是,有一件事使我感到恼火.
I have recently (e.g. just now) upgraded to XCode 4, and I like it overall, however, there is one thing that annoys me.
当我编写这样的代码时:
When I write code like this:
if (self = [super init])
{
...
}
它给了我一个问题":Using the result of an assignment as a condition without parentheses
It gives me an 'issue': Using the result of an assignment as a condition without parentheses
我如何抑制此警告,因为它以红色突出显示所有文本,使我认为存在严重错误.因为我是一位经验丰富的Objective-C编码人员,所以我真的不想改变自己的做法,并在init语句周围添加额外的括号.
How can I suppress this warning, as It underlines all the text in red, making me think that there is a critical error. As I am a somewhat seasoned Objective-C coder, I really don't want to change my practices and add extra parentheses around my init statements.
推荐答案
您可以在if语句中添加一组括号
You can either put an additional set of parentheses in the if statement
if ((self = [super init])) {
...
}
或者,您可以像新模板那样做.
Or, you can do as the new templates do.
self = [super init];
if(self) {
...
}
这篇关于XCode 4 if(self = [super init])问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!