hi guys, I try to write a ApiRequest class to handle common request settings and response data, here is a delete function I wrote below:
public static func delete<Parameters: Encodable>(_ convertible: URLConvertible, parameters: Parameters? = nil, success: @escaping (Data?)->Void, failure: @escaping (ApiError)->Void) {
debugPrint("ApiRequest.delete->")
debugPrint(convertible)
debugPrint("parameter-> \(parameters)")
AF.request(convertible, method: .delete, parameters: parameters).response{ response in
handleResponse(response, success: success, failure: failure)
}
}
I used an optional type-inferred parameter here. I got "Generic parameter 'Parameters' could not be inferred" error when I call this function without parameters:
ApiRequest.delete("\(WorkoutApi.routine_delete.rawValue)/\(id)",success: {response in
let index = self.routineList.firstIndex(where: { routine in
routine.id == id
})
if index != nil {
withAnimation(.spring()){
self.routineList.remove(at: index!)
}
}
}, failure: {error in
})
Somebody please help me!! How can I get this code right.Waiting online
Hope you could find some answer here:
Seems to be an open discussion :
https://forums.swift.org/t/default-values-for-generic-parameters/34020