objective c - How to treat NSArray of mixed content as of unified content? -
class b derived class a. class b overrides '- (nsstring *) description', overridden in class too. made new 'nsarray' of pointers instances, both class , class b.
is possible treat of them in cycle class instances, more precisely - possible use class '- (nsstring *) description' of them?
currently, use check if it's class b instance, , call initializer makes class instance in case. seems unnecessary, don't solution.
the following example may little easier on eyes solution in other thread mentioned in merlevede's answer.
for ( id item in array ) { if ( [item ismemberofclass:[classa class]] ) { nslog( @"%@", item ); } else { struct objc_super parent = { item, [item superclass] }; nslog( @"%@", objc_msgsendsuper( &parent, @selector(description) ) ); } }
the objc_msgsendsuper
function can used call method returns id
edit - forgot mention need
#import <objc/message.h>
edit 2 - based on feedback op in comments, here ultimate solution
for ( id item in array ) { struct objc_super baseclass = { item, [classa class] }; nslog( @"%@", objc_msgsendsuper( &baseclass, @selector(description) ) ); }
Comments
Post a Comment