for (UIView* att in bottomAttachments) { if (i <= [cells count]) { att = [[UIView alloc] extraStuff] } }
__strong做了什么以及为什么要添加它?
解决方法
If a variable is declared in the condition of an Objective-C fast enumeration loop,and the variable has no explicit ownership qualifier,then it is qualified with
const __strong
and objects encountered during the enumeration are not actually retained.Rationale
This is an optimization made possible because fast enumeration loops promise to keep the objects retained during enumeration,and the collection itself cannot be synchronously modified. It can be overridden by explicitly qualifying the variable with__strong
,which will make the variable mutable again and cause the loop to retain the objects it encounters.
正如Martin在评论中指出的那样,值得注意的是,即使使用__strong变量,通过重新分配它你也不会修改数组本身,但是你只需要将局部变量指向另一个对象.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。