I would like to pass a NSMutableArray by reference so that it can be altered by another method. What would be the correct syntax for this?
Thanks,
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Objective-C objects are always passed by reference (using pointers) – you can’t pass them by value.
I.e. the following is fine:
… and can be e.g. invoked like this:
There is also the possibility of passing a pointer by reference:
In that case
arrayis used as an out-parameter – you pass a reference to a pointer to receive an instance:… which could be called like so:
Using out-parameters is usually only seen if the return-value is already used and additional information has to be returned. An example would be error-information as dreamlax noted.