ios - Iterate through an NSArray of different classes that implement the same protocol with a for in loop -
i have method in instantiate array of objects derived same protocol. know if can iterate through array , execute common protocol method.
pseudocode
nsarray *implementations = @[/*impl1, impl2, impl3 instantiated here*/] (__________ * impl in implementations){ [impl protocolmethod] }
my issue don't know how define type of object in blank in for-in loop because different classes. closest can think of "id" doesn't seem valid type because "pointer non-const type no explicit ownership."
could this:
for (nsobject<myprotocol>* impl in implementations) [impl protocolmethod]
or even
for (id<myprotocol> impl in implementations) [impl protocolmethod]
i use first form it's bit more compile-time safe.
Comments
Post a Comment