When should one use "out" parameters?
- by qegal
In Objective-C, there are several methods like initWithContentsOfFile:encoding:error: where one passes in a reference to an NSError object for the error: parameter. In this example, the value of the NSError object passed in can change based on what goes on at runtime when the method is being called and whether the body of the method was executed in a certain way successfully. In a way I think of this NSError object as sort of like a second return value from the method, and only differs from an object anObject in the statement return anObject; in that when this statement is called, execution leaves the method.
So my question is, not only in the context of error handling in Objective-C, but in general, when should one use an "out" parameter in place of returning said value in a return statement?