Last active
January 6, 2016 14:50
-
-
Save nunogoncalves/7f23257f73a43900a751 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
protocol Getter { | |
typealias Element | |
func getUrl() -> String | |
func getDataFrom(dictionary: NSDictionary) -> Element | |
func get(success success: Element -> (), failure: NetworkStatus -> ()) | |
} | |
extension Getter { | |
func get(success success: Element -> (), failure: NetworkStatus -> ()) { | |
let qos = Int(QOS_CLASS_USER_INTERACTIVE.rawValue) | |
dispatch_async(dispatch_get_global_queue(qos, 0)) { | |
let responseHandler = ResponseHandler() | |
responseHandler.failureCallback = { status in | |
dispatch_async(dispatch_get_main_queue()) { | |
failure(status) | |
} | |
} | |
responseHandler.successCallback = { dictionary in | |
let data = self.getDataFrom(dictionary) | |
dispatch_async(dispatch_get_main_queue()) { | |
success(data) | |
} | |
} | |
Network.Requester(networkResponseHandler: responseHandler).makeGet(self.getUrl()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment