Re: What's NSError **?
Re: What's NSError **?
- Subject: Re: What's NSError **?
- From: Brian Webster <email@hidden>
- Date: Thu, 13 Nov 2003 22:13:46 -0600
You don't need to allocate anything to pass into those arguments, you
just need a pointer to which the method can write its response. An
example will show this the most clearly. To call this method, for
instance, you would write something like this:
- (void)doRequest
{
NSData* data;
NSURLResponse* urlResponse;
NSError* error;
NSURLRequest* myRequest;
//myRequest = whatever;
data = [NSURLConnection sendSynchronousRequest:myRequest
returningResponse:&urlResponse error:&error];
}
After calling the method, urlResponse and error will point to valid
objects (or nil, if appropriate) that were allocated by the method you
called. These objects will be autoreleased, so you don't need to
release them yourself, although of course you should retain them if you
need to keep them around.
For reference, the implementation of such a method on the inside would
look something like this:
+ (NSData*)sendSynchronousRequest:(NSURLRequest*)request
returningResponse:(NSURLResponse**)response error:(NSError**)error
{
NSURLResponse* myResponse;
NSError* myError;
//do a bunch of important stuff
myResponse = [[NSURLResponse alloc] init];
[myResponse autorelease];
*response = myResponse;
myError = [[NSError alloc] init];
[myError autorelease];
*error = myError;
return importantData;
}
On Nov 13, 2003, at 1:24 PM, Jason McInnes wrote:
OK, another fundamental question which I should know
the answer to, but...I'm new.
Anyway, the method declaration
+ (NSData *)sendSynchronousRequest:(NSURLRequest
*)request returningResponse:(NSURLResponse **)response
error:(NSError **)error
calls for an NSError ** and an NSURLResponse **...
Are these handles (pointers to pointers)? How do I
allocate those in Objective C?
I am assuming that when I call sendSynchronousRequest
I have to pass in allocated objects, rather than
unallocated handles. (I tried sending in unallocated
handles and got a bad access error.)
Since sendSynchronousReponse is supposed to set the
response and error by reference if necessary, how do I
construct the objects to pass in?
Jason
=====
Jason McInnes
2 Degrees
Cell: 206.849.3680
Email: email@hidden
__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.