Xcode warning “Property access results unused - getters should not be used for side effects”

后端 未结 4 1169
时光说笑
时光说笑 2021-02-01 00:31

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

My code is this:

-(void)nextLetter {
    // NSLog(@\"%s\", __FUNCTION__);
    currentLetter          


        
4条回答
  •  眼角桃花
    2021-02-01 01:09

    In newer Xcode versions, even the [object method]; may trigger the warning. But sometimes we actually do need to call a property and discard the result, for example when dealing with view controllers and we need to make sure the view is actually loaded.

    So we were doing:

    // Ensure view is loaded and all outlets are connected.
    [self view];
    

    This now also triggers the “Property access results unused - getters should not be used for side effects” warning. The solution is to let the compiler know it's done intentionally by casting the result type to void:

    (void)[self view];
    

提交回复
热议问题