简体   繁体   English

属性访问结果未使用

[英]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.

相关问题 调用方法时属性访问结果未使用错误 - Property access result unused error while invoking a method xCode:尝试创建密钥窗口时,“未使用属性访问结果” - xCode: “Property access result unused” when trying to make key window “未使用属性访问结果 - 不应将getter用于副作用”警告 - “Property access result unused - getters should not be used for side effects” warning 向LocatNotification错误添加变量是未使用属性访问结果-不应将吸气剂用于副作用 - Adding variable to LocatNotification error is Property access result unused - getters should not be used for side effects 如何禁用Xcode编译器警告“属性访问结果未使用-吸气剂不应用于副作用” - How to disable Xcode compiler warning “Property access result unused - getters should not be used for side effects” 不使用属性访问结果,但NSLog可以正常工作 - Property access results unused but NSLog works fine UIDocumentInteractionController中的“未使用表达结果” - “Expression Result Unused” in UIDocumentInteractionController 表达式结果未在for循环中使用 - expression result unused on for loop 表达结果未使用 - Expression result unused UITabBarItem未使用的表达式结果 - Expression result unused for UITabBarItem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM