Xcode警告“未使用属性访问结果-吸气剂不应用于副作用" [英] Xcode warning "Property access results unused - getters should not be used for side effects"

查看:68
本文介绍了Xcode警告“未使用属性访问结果-吸气剂不应用于副作用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调用本地例程时收到此警告.

I'm getting this warning when I'm calling a local routine.

我的代码是这样的:

-(void)nextLetter {
    // NSLog(@"%s", __FUNCTION__);
    currentLetter ++;
    if(currentLetter > (letters.count - 1))
    {
        currentLetter = 0;
    }
    self.fetchLetter;
}

我在self.fetchLetter语句上收到警告.

I'm getting the warning on the self.fetchLetter statement.

该例程如下:

- (void)fetchLetter {
    // NSLog(@"%s", __FUNCTION__);
    NSString *wantedLetter = [[letters objectAtIndex: currentLetter] objectForKey: @"langLetter"];

    NSString *wantedUpperCase = [[letters objectAtIndex: currentLetter] objectForKey: @"upperCase"];    


.....   
}

我更喜欢修正警告消息,是否有更好的方式编写此消息?

I prefer to fix warning messages, is there a better way to write this?

谢谢!

推荐答案

点表示法(即self.fetchLetter)用于属性,而不用于任意方法. self.fetchLetter被解释为获取'self'的'fetchLetter'属性",这不是您想要的.

The dot notation (i.e. self.fetchLetter) is meant for properties, not for arbitrary methods. The self.fetchLetter is being interpreted as "get the 'fetchLetter' property of 'self'," which isn't what you intend.

只需使用[self fetchLetter].

这篇关于Xcode警告“未使用属性访问结果-吸气剂不应用于副作用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆