-1

I have an NSMutableArray in which i want to add those objects which conforms the ObjectType. Is there any way i can get the ObjectType declared using light weight generics so when adding an object i can check whether the object is about to insert is ObjectType; if yes insert it else just forget it.

Thanks.

Dawood Mujib
  • 337
  • 4
  • 14
  • 2
    Can you please explain your question more in detail? – Er. Vihar Dec 16 '16 at 13:58
  • Not sure what you are asking but this [NSMutableArray - force the array to hold specific object type only](http://stackoverflow.com/questions/5197446/nsmutablearray-force-the-array-to-hold-specific-object-type-only) might help you. – CRD Dec 16 '16 at 15:33

1 Answers1

0

In Objective-C all type analysis is done at runtime and only at runtime. (The compiler gives warnings at compile time, but the produced code is bit-identical to code with any other object type.) The lightweight generics are for Swift. We didn't need that in the past 30 years. (Wow, this is really long in computer sciences.)

So, any code related to the mutable array with or without type specifier is identical. For Objective-C a static type information is the wrong thing. Even there would be a way to do that, it would be anticonceptual.

So: No.

Why do you want to do that? Don't do it.

Amin Negm-Awad
  • 16,582
  • 3
  • 35
  • 50
  • Let say i have different arrays for each type which holds thousands of objects each. I was think about to reduce the computation power by getting rid of introspection each time. – Dawood Mujib Dec 16 '16 at 14:10
  • I do not understand, why you need "introspection" each time. If you want to do some specific depending on the type, make a protocol, add this to the classes in a category and implement the methods differently. However, the runtime does introspection on every message dispatch. If you have a performance issue, make a new Q, show the code and one will help you. – Amin Negm-Awad Dec 16 '16 at 14:28