Skip to content

Instantly share code, notes, and snippets.

View jayesh15111988's full-sized avatar

Jayesh Kawli jayesh15111988

View GitHub Profile
@jayesh15111988
jayesh15111988 / TestableNetworkServiceExample.swift
Created November 28, 2023 07:45
A sample code to demonstrate how to use protocols to facilitate unit testing in iOS app
//
// TestableNetworkServiceExample.swift
// KayakCodingChallenge
//
// Created by Jayesh Kawli on 11/28/23.
//
import Foundation
import XCTest
@jayesh15111988
jayesh15111988 / NetworkService.swift
Last active November 28, 2023 07:39
A code for demonstrating how to use URLSession to send network request from iOS app
struct Name: Decodable {
let firstName: String
let lastName: String
}
final class NetworkService {
func loadSampleData(completion: @escaping (Result<Name, Error>) -> Void) {
let url = URL(string: "www.google.com")!
@jayesh15111988
jayesh15111988 / RequestHandlerTests.swift
Created May 3, 2023 16:53
A full source code for tests for network stack on iOS and Swift
// JSONDataReader.swift
import XCTest
final class JSONDataReader {
static func getDataFromJSONFile(with name: String) -> Data? {
guard let pathString = Bundle(for: self).path(forResource: name, ofType: "json") else {
XCTFail("Mock JSON file \(name).json not found")
return nil
}
@jayesh15111988
jayesh15111988 / RoundedCornerBorderAndShadowStyles.swift
Created May 2, 2023 16:32
A source code to demonstrate how to apply rounded corner, rounded borders and shadow to a SwiftUI view
// An utility view extension
extension View {
@ViewBuilder
func `if`<Transform: View>(_ condition: Bool, transform: (Self) -> Transform) -> some View {
if condition { transform(self) }
else { self }
}
}
@jayesh15111988
jayesh15111988 / MockDispatchQueue.swift
Created May 2, 2023 08:23
A source code on how to implement DispatchQueue mock for unit testing in the iOS app
// A protocol for mocking DispatchQueue instance
protocol DispatchQueueType {
func async(execute work: @escaping @convention(block) () -> Void)
}
// Confirming existing DispatchQueue to DispatchQueueType
extension DispatchQueue: DispatchQueueType {
func async(execute work: @escaping @convention(block) () -> Void) {
async(group: nil, qos: .unspecified, flags: [], execute: work)
@jayesh15111988
jayesh15111988 / CustomViewDidLoad.swift
Last active May 1, 2023 18:53
A source code to demo view did load behavior on SwiftUI view
import SwiftUI
struct CustomViewDidLoad: View {
var body: some View {
VStack {
Text("Hello")
}
}
@jayesh15111988
jayesh15111988 / RequestHandler.swift
Created May 1, 2023 09:58
An implementation for building a network stack on iOS using Swift
import Foundation
enum APIRouteDomain {
case userLoginManagement(APIRoute)
case accountInfoManagement(APIRoute)
case accountManagement(APIRoute)
var associatedApiRoute: APIRoute {
switch self {
case .userLoginManagement(let apiRoute), .accountInfoManagement(let apiRoute), .accountManagement(let apiRoute):
@jayesh15111988
jayesh15111988 / InfiniteLoadingScreen.swift
Created April 30, 2023 10:10
A SwiftUI, Swift and iOS source code to demonstrate working of infinite loading screen with pagination
//
// InfiniteLoadingScreen.swift
// Test
//
// Created by Jayesh Kawli on 1/12/23.
//
import SwiftUI
struct Employee: Identifiable, Equatable {
@jayesh15111988
jayesh15111988 / VerticalScrollView.swift
Created April 22, 2023 11:14
A source code for demonstrating working of a vertically scrolling content view
class VerticalScrollView : UIViewController {
init() {
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@jayesh15111988
jayesh15111988 / HorizontalScrollView.swift
Created April 22, 2023 10:55
A source code for horizontally scrolling content view
//
// HorizontalScrollView.swift
// Test
//
// Created by Jayesh Kawli on 4/21/23.
//
import UIKit
class HorizontalScrollView : UIViewController {