开发者

Using NSArray's makeObjectsPerformSelector to have side effects

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 doI开发者_如何学Got 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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜