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
class LoginController:UIViewController { | |
private func loginUser() { | |
ServiceController().loginUser(request: LoginRequest(email: emailTF.text, password: passwordTF.text)) {[weak self] (result) in | |
self?.dismissProgressBar() | |
guard let self = self else { return } | |
switch result { | |
case .success(let response): | |
print("login success \(response)") | |
break |
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
// Possible request types | |
private enum ServiceType:String { | |
case GET | |
case POST | |
case PUT | |
case DELETE | |
case PATCH | |
} | |
struct ServiceController:NetworkingController { |
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
protocol NetworkingController { | |
func loginUser(request:LoginRequest,completion:@escaping(_ result:Result<LoginResponse,NetworkControllerError>) -> Void) | |
func forgotPassword(request:ForgotPasswordRequest,completion:@escaping(_ result:Result<ForgotPwdResponse,NetworkControllerError>) -> Void) | |
} | |
enum NetworkControllerError:Error { | |
case Non200StatusCodeError(NetworkError) | |
case NoNetworkError | |
case BadURLError | |
case UnParsableError |
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
struct LoginResponse:Decodable { | |
let isSuccess:Bool | |
let error:NetworkError? | |
} | |
struct LoginRequest:Encodable { | |
let email:String? | |
let password:String? | |
} |
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
protocol NetworkingController { | |
func verifyUserLogin(_ req: Loginrequest, completion: @escaping (LoginResponse?, NetworkError?) -> Void) | |
} |
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
class ViewController:CustomNavigationbarProtocol { | |
override func viewDidLoad() { | |
//set navigation bar using the protocol method created | |
self.setNavigationbartype(.NavCenterTitleWithBackButton,"First Page",#selector(onBackBtn),nil) | |
} | |
@objc func onBackBtn() { | |
self.navigationController.popViewController(animated:true) | |
} | |
} |
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
fileprivate enum ServiceType:String { | |
case GET,POST,PUT,DELETE | |
} | |
struct APIController:NetworkProtocol { | |
func verifyUserLogin(_ req: Loginrequest, completion: @escaping (LoginResponse?, NetworkError?) -> Void) { | |
networkRequestResult(urlString: Constants.API_NEW_PATIENT, type: .POST, header: nil, encodingData: req, completion: completion) | |
} | |
} |
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
struct LoginRequest:Encodable { | |
var username:String? | |
var password:String? | |
} |
NewerOlder