[英]Property access result unused
I just started learning Objective-C yesterday, and i can't quite figure out this warning: 我昨天才刚开始学习Objective-C,但我不太明白这个警告:
Property access result unused - getters should not be used for side effects
Using this code (line 3 gives the warning, self.addItem()): 使用此代码(第3行给出警告self.addItem()):
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.itemTxt) {
self.addItem;
self.itemTxt.text = @"";
}
return YES;
}
- (IBAction)addItem {
[self.model addItemToArray: _itemTxt.text];
_itemTxt.text = @"";
}
Why am I getting this warning? 为什么会收到此警告?
What is addItem. 什么是addItem。 According to your code, it seems you're trying to call that function so use this:
根据您的代码,您似乎正在尝试调用该函数,因此请使用以下代码:
[self addItem];
One more thing basically, if you see in depth about IBAction, you'll find it's void. 基本上,还有一件事,如果深入了解IBAction,就会发现它无效。 Normally, we use IBAction when we want to use IB for event fire.
通常,当我们要使用IB进行事件触发时,我们使用IBAction。
So, you can use(if you need to call manually) 因此,您可以使用(如果需要手动致电)
- (void)addItem {
[self.model addItemToArray: _itemTxt.text];
_itemTxt.text = @"";
}
Hope, it'll enhance your knowledge and will assist in your warning. 希望它会增强您的知识,并会帮助您进行警告。
To call the function use 调用函数使用
[self addItem];
When you're using self.addItem you're accessing a variable named addItem. 当您使用self.addItem时,您正在访问一个名为addItem的变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.