pdiddy
pdiddy

Reputation: 6297

NSURLConnection didFailWithError connectionDidFinishLoading called at same time?

Regarding "didFailWithError" and "connectionDidFinishLoading"

Can they both be called? Or its always one or the other?

Upvotes: 3

Views: 1772

Answers (3)

erkanyildiz
erkanyildiz

Reputation: 13224

No, they cannot be called at the same time.

After the delegate receives a message connection:didFailWithError:, it receives no further delegate messages for the specified connection.

If the connection succeeds in downloading the request, the delegate receives the connectionDidFinishLoading: message. The delegate will receive no further messages for the connection and the NSURLConnection object can be released.

http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

Upvotes: 6

rmaddy
rmaddy

Reputation: 318854

While not obvious, the docs make a statement that only one of these two will be called. It either finishes successfully and connectionDidFinishLoading is called, or it fails with an error and didFailWithError is called. You can find this in the NSURLConnectionDataDelegate docs for the **connection:willSendRequest:redirectResponse: method.

Edit: It looks like the answer from @erkanyildiz shows the better info from the docs.

Upvotes: 3

BergP
BergP

Reputation: 3545

From docs https://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html

connectionDidFinishLoading:

Sent when a connection has finished loading successfully.

Successfully. Seems like always one or the other.

Upvotes: 1

Related Questions