Passing arguments by value or by reference in objective C

Posted by Rafael on Stack Overflow See other posts from Stack Overflow or by Rafael
Published on 2010-05-23T16:31:24Z Indexed on 2010/05/23 16:41 UTC
Read the original article Hit count: 861

Hello, I'm kind of new with objective c and I'm trying to pass an argument by reference but is behaving like it were a value. Do you know why this doesn't work?

This is the function:

- (void) checkRedColorText:(UILabel *)labelToChange {
    NSComparisonResult startLaterThanEnd = [startDate compare:endDate];
    if (startLaterThanEnd == NSOrderedDescending){
        labelToChange.textColor = [UIColor redColor];
    }
    else{
        labelToChange.textColor = [UIColor blackColor];
    }

}

And this the call:

UILabel *startHourLabel; (this is properly initialized in other part of the code)
[self checkRedColorText:startHourLabel];

Thanks for your help

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about pass-by-reference