> On Oct 18, 2017, at 14:18, Jens Alfke <j...@mooseyard.com 
> <mailto:j...@mooseyard.com>> wrote:
> 
> 
> 
>> On Oct 17, 2017, at 5:06 PM, dangerwillrobinsondan...@gmail.com 
>> <mailto:dangerwillrobinsondan...@gmail.com> wrote:
>> 
>> Isn’t NSHTTPURLResponse a subclass of NSURLResponse?
> 
> Yes it is, but calling `((NSHTTPURLResponse*)response).statusCode` will still 
> throw an exception if the response isn’t actually an instance of the 
> subclass, because the base class doesn’t implement that property.
> 
> —Jens


That's exactly the point I think.
The docs and call signature mostly say you'll get NSURLResponse, but that it 
will be NSHTTPURLResponse if your request was HTTP or HTTPS.
Perhaps there is a bug.
Either a docs bug worth filing if it should say you should always check if the 
response is an NSHTTPURLResponse or that it responds to selector statusCode
Or a functional bug where sometimes it's not working.



Sample code here shows the completionHandler passing an NSURLResponse not 
necessarily a subclass.
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/UsingNSURLSession.html
 
<https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/UsingNSURLSession.html>

The docs for dataTaskWithURL:completionHandler: say 
response
An object that provides response metadata, such as HTTP headers and status 
code. If you are making an HTTP or HTTPS request, the returned object is 
actually an NSHTTPURLResponseobject.

The docs show the signature as this
- (NSURLSessionDataTask 
<https://developer.apple.com/documentation/foundation/nsurlsessiondatatask?language=objc>
 *)dataTaskWithURL:(NSURL 
<https://developer.apple.com/documentation/foundation/nsurl?language=objc> 
*)url 
                        completionHandler:(void (^)(NSData 
<https://developer.apple.com/documentation/foundation/nsdata?language=objc> 
*data, NSURLResponse 
<https://developer.apple.com/documentation/foundation/nsurlresponse?language=objc>
 *response, NSError 
<https://developer.apple.com/documentation/foundation/nserror?language=objc> 
*error))completionHandler;


That does indeed seem to imply that it would return an NSURLResponse as a 
generality, but that you will in fact have an NSHTTPURLResponse object if your 
request was HTTP or HTTPS.

Docs for dataTaskWithRequest:completionHandler: the same in all those key areas.
Docs for downloadTaskWithURL:completionHandler: same.
Docs for downloadTaskWithRequest:completionHandler: same.
Docs for downloadTaskWithResumeData:completionHandler: same.
Docs for uploadTaskWithRequest:fromData:completionHandler: same.
uploadTaskWithRequest:fromFile:completionHandler:


Docs for URLSession:dataTask:didReceiveResponse:completionHandler: get a little 
vague but the signature says NSURLResponse.
URLSession:dataTask:didReceiveResponse:completionHandler: also vague.
URLSession:dataTask:willCacheResponse:completionHandler: also vague, but 
NSCachedURLResponse seems a bit different.

 


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (Macnetworkprog@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/macnetworkprog/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to