Can a function return an object? Objective-C and NSMutableArray
        Posted  
        
            by seaworthy
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by seaworthy
        
        
        
        Published on 2010-04-16T17:12:03Z
        Indexed on 
            2010/04/16
            17:13 UTC
        
        
        Read the original article
        Hit count: 431
        
I have an NSMutableArray. It's members eventually become members of an array instance in a class. I want to put the instantiantion of NSMutable into a function and to return an array object. If I can do this, I can make some of my code easier to read. Is this possible?
Here is what I am trying to figure out.
//Definition:
    > function Objects (float a, float b) {
    >   NSMutableArray *array = [[NSMutableArray alloc] init];
    >   [array addObject:[NSNumber numberWithFloat:a]];
    >   [array addObject:[NSNumber numberWithFloat:b]];  
    >  //[release array]; ????????
       return array;
    > }
//Declaration:
 Math *operator = [[Math alloc] init];
    [operator findSum:Objects(20.0,30.0)];
My code compiles if I instantiate NSMutableArray right before I send the message to the receiver. I know I can have an array argument along with the method. What I have problem seeing is how to use a function and to replace the argument with a function call. Any help is appreciated. I am interested in the concept not in suggestions to replace the findSum method.
© Stack Overflow or respective owner