Skip to content

Instantly share code, notes, and snippets.

View jmarkstar's full-sized avatar
🏠
Working from home

Marco Estrella jmarkstar

🏠
Working from home
View GitHub Profile
/*
I want to create a Cooler that supports many kind of drinks but the principals drinks are Jolt energy drinks for mine and caffeine free diet coke for my girlfriend.
If I took an incorrect drink, I will put it again in the cooler, If I took the correct one, I will drink it.
*/
//using enums to limit the size of cans
enum DrinkSize {
case Can12
case Can16
case Can24
@jmarkstar
jmarkstar / AlamofireCodable.swift
Last active June 6, 2023 16:45
Decode Alamofire response to a Generic codable type but if we get http code 400, I decode different json which is a error message.
@discardableResult
private func performRequest<T:Decodable>(route: APIRouter, decoder: JSONDecoder = JSONDecoder(), completion:@escaping (Int, Result<T>)->Void) -> DataRequest {
return Alamofire.request(route).responseData() { responseData in
guard let response = responseData.response else {
completion(APIClient.responseErrorCode, .failure(ApiError.internalServerError(NSLocalizedString("service_error", comment: AppConstant.EMPTY))))
return
}