[報錯]Fast enumeration variables cannot be modified in ARC by default; declare the variable __strong to allow this


 

今天寫了下面的快速枚舉for循環代碼,從按鈕數組subButtons中取出button,然后修改button的樣式,在添加到view中

for (UIButton *button in subButtons) {
     button.selected = YES;
     button = [self updateStatusWithButton:button];
     [self.view addSubview:button];
}

 

但是寫完還未編譯,就報如下錯誤:

Fast enumeration variables cannot be modified in ARC by default; declare the variable __strong to allow this

即: 快速枚舉變量在ARC下默認不能修改其引用屬性,聲明變量為__strong允許修改

 所以修改如下即可:

for (__strong UIButton *button in subButtons) {
            button.selected = YES;
            button = [self updateButtonStatusWithButton:button isInitial:YES];
            [self.view addSubview:button];
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM