When is a NSURLResponse not a NSHTTPURLResponse?

前端 未结 2 1128
心在旅途
心在旅途 2021-02-12 22:24

I\'ve seen a lot of code, including Apple\'s SimpleURLConnections sample, that simply cast any NSURLResponse to a NSHTTPURLResponse. If it is always a NSHTTPURLResponse why do t

2条回答
  •  后悔当初
    2021-02-12 22:40

    The safer way to do it is with introspection.

    if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
       NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)redirectResponse;
       // do stuff
    }
    

提交回复
热议问题