Lefora Free Forum
login join
Loading
389 views

**'s

Page 1
1–4
?
63 posts

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?

__________________
kompilesoft

come and see my website! it's real cool reviews
novice - member
27 posts


It represents a pointer to a two dimensional array.  Therefore *** would represent a pointer to a three dimensional array.

?
288 posts

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.

__________________
?
63 posts

OK, thanks. I think I understand now. Weird though (horrible)

__________________
kompilesoft

come and see my website! it's real cool reviews
Page 1
1–4

Locked Topic


You must be a member to post in this forum

Join Now!