Skip to content

Instantly share code, notes, and snippets.

protocol viewAnimatable {
func animateView(duration:TimeInterval)
}
extension viewAnimatable where Self:UIView {
func animateView(duration:TimeInterval) {
UIView.animate(withDuration: duration, animations: {
self.alpha = 0.5
}) { (_) in
self.alpha = 1.0
@bharathreddys77
bharathreddys77 / LoginRequest.swift
Last active February 10, 2020 10:54
API Request
struct LoginRequest:Encodable {
var username:String?
var password:String?
}
@bharathreddys77
bharathreddys77 / APIController.swift
Last active May 23, 2021 07:12
Network Controller
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)
}
}
@bharathreddys77
bharathreddys77 / CustomNavigationBar.swift
Last active October 27, 2020 11:19
Type of Navigation bar
//Define different types of navigation bar application requires
enum NavigationbarType {
case NavPlainBackButton
case NavCenterTitleImageWithNoBackButton
case NavCenterTitleWithBackButton
case NavWithTitleOnly
case NavWithLocationSearch
}
@bharathreddys77
bharathreddys77 / CustomNavigationBar.swift
Created October 27, 2020 11:28
Navigation bar items
fileprivate func setOriginalBackImage(selector:Selector) {
let backButton = UIBarButtonItem(image: UIImage(named: "nav_back_btn")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: selector)
backButton.tintColor?.withAlphaComponent(0.3)
self.navigationItem.leftBarButtonItem = backButton
}
fileprivate func setOnlyTitleWithoutBackButton(title:String) { // just display title on nav bar without back button
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 150, height: 44))
label.text = title
label.font = UIFont(name: Constants.MabryFonts.REGULAR, size: 16)
@bharathreddys77
bharathreddys77 / ViewController.swift
Created April 26, 2021 11:43
Controller adopted for Navigation bar protocol
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)
}
}
protocol NetworkingController {
func verifyUserLogin(_ req: Loginrequest, completion: @escaping (LoginResponse?, NetworkError?) -> Void)
}
@bharathreddys77
bharathreddys77 / LoginModel.swift
Created May 23, 2021 07:17
Encodable login request and Decodable login response
struct LoginResponse:Decodable {
let isSuccess:Bool
let error:NetworkError?
}
struct LoginRequest:Encodable {
let email:String?
let password:String?
}
@bharathreddys77
bharathreddys77 / NetworkingController.swift
Last active May 23, 2021 08:01
Create a network protocol which will be the blue print of all API methods. This file also has a network error Error type which provides possible fails of the API.
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
@bharathreddys77
bharathreddys77 / ServiceController.swift
Last active May 23, 2021 08:02
ServiceController triggers API and fetch data. This file implements NteworkController protocol
// Possible request types
private enum ServiceType:String {
case GET
case POST
case PUT
case DELETE
case PATCH
}
struct ServiceController:NetworkingController {