CLang 错误(目标 C):初始化期间存储的值永远不会被读取
Foo *oFoo = [[[Foo alloc] init] autorelease];
这就是我被教导用 Objective C 编程的方式,但 CLang 错误检查器抱怨从未读取初始值。但 oFoo 是一个具有属性的对象。 oFoo 本身没有单一值。财产价值才是最重要的。
oFoo.PropertyA = 1;
oFoo.PropertyB = @"Hello, World."
我应该忽略这个吗?这值得修复吗?鉴于“初始值”在我的上下文中毫无意义,解决方法是什么?
Foo *oFoo = [[[Foo alloc] init] autorelease];
This is how I was taught to program in Objective C, yet the CLang error checker complains that the initial value was never read. But oFoo is an object with properties. oFoo itself has no single value. The property values are what matter.
oFoo.PropertyA = 1;
oFoo.PropertyB = @"Hello, World."
Should I just ignore this? Is this worth fixing? What is the fix, seeing that "initial value" is meaningless in my context?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常这意味着:
对于简单类型:
从不使用第一个值 (2)。类似的事情也可能发生在对象上,例如:
这里第一个 alloc-init 块创建了一个被第二个 alloc-init 覆盖的值。错误告诉我们类似的事情。
我可以关闭方法实现,而不是第二个 alloc-init 块,这将是类似的。
Usually that means:
For a simple type:
First value (2) is never used. Similar things can happen with objects, for example:
Here first alloc-init block created a value that was overridden by second alloc-init. And error tells something like that.
Instead of second alloc-init block I can close method implementation, that will be similar.
我认为亚历山大·巴巴耶夫可能是对的。这是实际代码:
aPart 是 Part 对象的数组。也许我应该删除第一行,最后一行应该如下所示:
如果我这样做,我不必在循环结束时显式释放 oPart。通过在循环开始之前声明 oPart,我试图提高效率并重用 oPart 对象,而不是每次循环时创建/释放。
有人知道哪种方法更好?
I think Alexander Babaev may be right. Here's actual code:
aPart is an array of Part objects. Maybe I should eliminate the first line and the last line should look like this:
If I do that, I DO NOT have to explicitly release oPart at the end of the loop. By declaring oPart before the loop begins, I was trying to be efficient and just reuse the oPart object, rather than create/release each time through the loop.
Anybody know which is the better approach?