2

I dont undesratand in which situations is more convenient to pass references as functions parameters:

- (void)exportXMLToString:(NSMutableString **)aString

Can I just pass the string by value and have it back when the method finishes to execute ?

Thanks

3 Answers 3

1

You may find the following thread useful. I think your issue is vastly discussed here: Use of pass by reference in Objective-C

Sign up to request clarification or add additional context in comments.

Comments

0

It more convenient to pass references when you do not want an extra copy of String, Extra copy means more space, If you want to read/append the String< It is better if you do not create a new new one. You easily do this by passing String value (create a new one) but that's not very efficient. (you want two glasses space to store 1/2 glass of water :) )

Comments

0

As I understand what you are trying to achieve, you could just name your method - (NSString *)xmlStringValue.

It is a matter of style, I personally only use references in ObjC when I have to (it is not really in the spirit of the language imho), and almost exclusively for (NSError **).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.