Passing with `&`

October 4th, 2011

In Objective-C you pass by reference by placing the "&" symbol (minus the quote marks) in-front of the variable name i.e. &var instead of just var . This informs the compiler to pass the memory address of the variable rather than its value. This is useful when you want to update that variable value but the method may also produce an error, rather than "overloading" the return value to handle both a successful and unsuccessful execution (an any casting issues that may then crop up), you simply allow the method to directly set the variable for you by passing that variables memory address.

What do you think? Let me know by getting in touch on Twitter - @wibosco