restrict NSArray to having only one kind of object
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.
精彩评论