Arguments by reference in Objective-C

后端 未结 5 743
孤城傲影
孤城傲影 2020-12-09 04:18

I\'m trying to pass an NSString by reference but it doesn\'t work.

This is the function:

+(void)fileName:(NSString *) file
{
    file =          


        
5条回答
  •  隐瞒了意图╮
    2020-12-09 04:28

    Passing a pointer to your object is the Objective C (and C) way of passing by reference.

    I agree with 'bbum' that a perceived need to pass by reference is a signal to think about what you are doing; however, it is by no means the case that there are not legitimate reasons to pass by reference.

    You should not create classes willy-nilly every time you have a function or method that needs to return more than one value. Consider why you are returning more than one value and if it makes sense to create a class for that then do so. Otherwise, just pass in pointers.

    -Just my 2 cents

提交回复
热议问题