Pretty late to the party here, but I wrote a pod for our internal apps that does pretty much exactly this - https://cocoapods.org/pods/OfflineRequestManager. The actual network request is still handled by whatever conforms to the OfflineRequest protocol, but the pod provides a simple way to enqueue the requests and ensure that they keep attempting to execute until they succeed, including saving to disk.
The simplest use case would look something like the following, though most actual cases (saving to disk, specific request data, etc.) will have a few more hoops to jump through:
import OfflineRequestManager
class SimpleRequest: OfflineRequest {
func perform(completion: @escaping (Error?) -> Void) {
doMyNetworkRequest(withCompletion: { response, error in
handleResponse(response)
completion(error)
})
}
}
///////
OfflineRequestManager.defaultManager(queueRequest: SimpleRequest())