When should one use "out" parameters?
Posted
by
qegal
on Programmers
See other posts from Programmers
or by qegal
Published on 2012-12-05T01:25:28Z
Indexed on
2012/12/05
5:29 UTC
Read the original article
Hit count: 260
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?
© Programmers or respective owner