The answer to @bbum is probably correct, but does not take into account one aspect of the question that I see there. There are many examples in Foundation that use pointers in a method signature, so you can say that this is a common pattern. And this is probably not a beginner's mistake.
Most of these examples are similar in that they fall into one category: the API tries to avoid using exceptions and instead use NSError
for crashes. But since the return value is used for BOOL
, which indicates success, an NSError
pointer is used as the output parameter. Only in the case of a rare error is an NSError
object created, which can contain error codes and error descriptions, as well as localized descriptions and possibly even more information (for example, an array of several errors in the case of mass operations). Thus, the main success case is effective, and in the event of an error, there is some ability to report what went wrong without resorting to exceptions. This is the justification for these signatures, as I understand it.
Examples of this use can be found in both NSFileManager
and NSManagedObjectContext
.
You might be tempted to use pointers in other cases where you want multiple return values ββand an array to not make sense (for example, because the values ββare not of the same type), but as @bbum said, this is most likely better look for alternatives.
source share