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

aneuryzm
  • 63,052
  • 100
  • 273
  • 488

3 Answers3

1

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

Community
  • 1
  • 1
rshahriar
  • 2,440
  • 1
  • 15
  • 5
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 :) )

maaz
  • 4,371
  • 2
  • 30
  • 48
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 **).

cdelacroix
  • 1,289
  • 14
  • 26