开发者

restrict NSArray to having only one kind of object

开发者 https://www.devze.com 2023-01-29 05:21 出处:网络
i have two class Screen and control. now in screen class i have declare one NSArray variable and this variable should only contain c开发者_StackOverflow中文版ontrol type object only(in c like control

i have two class Screen and control. now in screen class i have declare one NSArray variable and this variable should only contain c开发者_StackOverflow中文版ontrol type object only(in c like control[]) how could i achieve this functionality?????


You can't configure NSArray to do this. Write a 'collection' class that wraps over the NSArray and set it up to handle only objects of type Control.


Objective-C does not have type-safe collections. Most people do fine without them. If you really insisted, you could wrap a regular array and check object classes upon inserting. It’s probably not worth it.

0

精彩评论

暂无评论...
验证码 换一张
取 消