Reputation: 615
i'm learning swift and found these protocol-delegate methods for connection:
func connection(connection: NSURLConnection!, didFailWithError error: NSError!)
and 3 more... so they start as
connection.start()
But there are also block structure:
NSURLConnection.sendSynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
So difference with "sendAsynchronousRequest" i understand, but what's difference with this block method and what is a best practice ?
Upvotes: 0
Views: 390
Reputation: 72
My understanding both are Asynchronous operation .
Delegate Methods : If you want to monitor the status of connection and recieveing data use delegate methods
Blocks: If you dont want to monitor and only need to perform some operation when the data has been fully received use blocks .
Hope that helps!
Upvotes: 1