// // NSObjectHOMAdditions.h // HigherOrderMessaging // // Created by Ofri Wolfus on 10/09/05. // Copyright 2005 Ofri Wolfus. All rights reserved. // #import @interface NSObject (NewHOM) /*! * @abstract Peforms the passed message and returns the result(s) (if it's an object) or the receiver. * @discussion This method accepts messages with iterated arguments returned from the -each method. * If iterated arguments are passed with the message, and the message returns an object, an array with all the results will be returned. * This method is an equivalent to repeatOf:message for:1. * You can use this method as an alternative to -ifResponds as long as the return type of the message is id. * If the return type is not id, nil will be returned but the message will still be sent. */ - (id)do:(Message *)message; /*! * @abstract Peforms the passed message x times, and returns the result(s) (if it's an object) or the receiver. * @discussion This method accepts messages with iterated arguments returned from the -each method. * If iterated arguments are passed with the message, and the message returns an object, an array with all the results will be returned. * The results of all messages sent during the execution of this method will be returned in a single array (only if the return type is id). * This method is specifically useful when allocating a bunch of instances at once, e.g. NSArray *uninitializedStrings = [NSString repeatOf:MSG(alloc) for:5];, * or combined with the -collect method to get an array of fully initialized instances: NSArray *strings = [[NSString repeatOf:MSG(alloc) for:5] collect:MSG(initWithString:@"Hello")]; * This method is an equivalent to for:NULL from:0 to:1 do:msg. * @param xTimes The number of times the receiver will process the message. */ - (id)repeatOf:(Message *)msg for:(int)xTimes; /*! * @abstract Peforms the passed message x times, and returns the result(s) (if it's an object) or the receiver. * @discussion This method is an extended version of the -repeatOf:for: method that allows you to use the counter of the iteration in your message. * Example: int i; NSArray *values = [NSValue for:&i from:-10 to:10 do:MSG(valueWithBytes:&i objCType:@encode(int))]; * In the example above, the value of i will be set to -10, and increased (up to 9) before each execution of the passed message. * Pass in NULL as the counter to ignore it. */ - (id)for:(int *)counter from:(int)start to:(int)end do:(Message *)message; /*! * @abstract Performs the passed message only if the receiver responds to it, and returns the result. * @discussion If the receiver doesn't respond to the passed message, nil will be returned. */ - (id)receive:(Message *)msg; @end