I'm creating an app where i call my API through this function:
func serverCallAPI(function:String,
success:((result:NSDictionary) -> Void)?) -> Void {
//code here to set up request to send with NSURLConnection
let connection:NSURLConnection = NSURLConnection(request: request,
delegate: self,
startImmediately: true)!
//I WANT TO RUN THE PASSED ON SUCCESS FUNCTION WHEN connectionDidFinishLoading IS CALLED.
}
- I need to use NSURLConnection to update my UI when fetching the data
- I might have a queue with serverCallAPIs waiting in line to be run, every single now with their own success function. The final function needs to be able to do that
- It needs to cancel if the connection fails. Perhaps something with a dispatch or NSOperation? I'm lost on this one... :(
My problem is that I cannot think of a way to call the passed on success function when connectionDidFinishLoading is done processing. How can you do that?