**'s
Hi all
Some methods I've found go like this:
-(NSString *)doSomething:(NSString *)input error:(NSError **)error;
My question is, why is there 2 * after the error thing?
It represents a pointer to a two dimensional array. Therefore *** would represent a pointer to a three dimensional array.
Routers is about right here. The story is like this. An NSError* error is a pointer a error object. When you can a thing like:
NSString* string = @"who's been eating my porridge";
NSError* error = nil ;
NSData* data = [file readSomethingFrom:string error:&error] ;
The problem is that you can't return data and error from the same function because the function only has one return value - the data.
So, if you want to return data and an error object, the (horrible hack) used is to return the data, and pass a pointer to an error object &error. The function readSomethingFrom: error: can create an error object and effectively return it on the pointer.
If you think this is horrible (and it is), you'll have to take it up with K&R who blessed C with this way of doing things in 1968. C++ addresses this shortcoming of C using references, however Obj/C is basically C and doesn't know anything about references.
OK, thanks. I think I understand now. Weird though (horrible)