Set bool property of all objects in the array

霸气de小男生 提交于 2019-11-29 12:02:57

Is there any better way to achieve this without implementing a custom public method?

This sounds like you are asking for opinion, so here is mine: Keep it simple.

for (PhotoItem *item in _photoItemArray)
    item.isSelected = YES;

Why obfuscate a simple thing with detours through obscure methods when you can write code that anybody will immediately understand?

Another way of doing the same thing would be:

[_photoItemArray setValue:@YES forKey:@"isSelected"];

This does not need the custom additional setter method because KVC does the unboxing for you.

But again I would vote against using such constructs. I think they are distracting from the simple meaning and confusing developers that come after you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!