views:

133

answers:

1

I have an NSArray of Foos in an Objective-C program. I would like to call the doIt function of each Foo, however, the makeObjectsPerformSelector function of NSArray does not allow the original Foos to be modified, per the docs. The doIt selector changes the m data member for each Foo when doIt is called. How do I go about efficiently performing this function on each Foo in the NSArray?

@interface Foo : NSObject {
    NSString *m;
}

@property (nonatomic, retain) NSString *m;

-(void)doIt;

@end
+6  A: 

You're allowed to modify the original Foos, just not the array itself. As you linked to in the documentation:

The method must not take any arguments, and must not have the side effect of modifying the receiving array.

Good luck!

Carl Norum
Thanks. After writing the question I found http://stackoverflow.com/questions/563051/nsarray-makeobjectsperformselector on SO but for some reason it did not show up in the "similar questions" field.
Mat