So, I saw this:
error:(NSError **)error
in the apple doc’s. Why two stars? What is the significance?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A ‘double star’ is a pointer to a pointer. So
NSError **is a pointer to a pointer to an object of typeNSError. It basically allows you to return an error object from the function. You can create a pointer to anNSErrorobject in your function (call it*myError), and then do something like this:to ‘return’ that error to the caller.
In reply to a comment posted below:
You can’t simply use an
NSError *because in C, function parameters are passed by value—that is, the values are copied when passed to a function. To illustrate, consider this snippet of C code:The reassignment of
xinf()does not affect the argument’s value outside off()(ing(), for example).Likewise, when a pointer is passed into a function, its value is copied, and re-assigning will not affect the value outside of the function.
Of course, we know that we can change the value of what
zpoints to fairly easily:So it stands to reason that, to change the value of what an
NSError *points to, we also have to pass a pointer to the pointer.