Skip to content

Instantly share code, notes, and snippets.

@bishalg
Last active January 25, 2024 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bishalg/ffaf0d90bd0e9d05f4db0285b2e5418a to your computer and use it in GitHub Desktop.
Save bishalg/ffaf0d90bd0e9d05f4db0285b2e5418a to your computer and use it in GitHub Desktop.
Network Request Class for Alamofire using Router URLRequest and Response as SwiftyJSON - JSON
//
/// Router -
/// https://gist.github.com/bishalg/4d554cd79a138c43c00c17cebf6eb3d3
//
/// Alamofire - Swifty JSON Response Parser
/// https://gist.github.com/bishalg/0561c81f921858725731f2c36819e99c
///
import Foundation
import SwiftyJSON
import Alamofire
typealias ObjectsCallBack = ([T]) -> Void
typealias ErrorCallback = (NSError) -> Void
class Request {
static func mostRecent(
onSuccess: ObjectsCallBack? = nil,
onError: ErrorCallback? = nil) {
let route = ActivitieRouter.activityDate(activitiesDate: ActivitiesDate.recentMonth)
let _ = Alamofire.request(route)
.responseSwiftyJSON { request, response, json, error in
guard error == nil else { return }
// create - objects array or object
// return - objects
onSuccess?(objects)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment