Skip to content

Instantly share code, notes, and snippets.

View tengfoung's full-sized avatar

Teng Foung tengfoung

View GitHub Profile
@tengfoung
tengfoung / MockAlamofire.md
Created May 22, 2025 23:47
Mock Alamofire

Dynamic API Mock Environment in Swift with Alamofire

This guide shows how to create a dynamic API mock environment in Swift using Alamofire. You can intercept and respond to requests using a custom URLProtocol, allowing you to return mock data instead of making real network calls — ideal for testing or development.


✅ Steps to Implement a Dynamic API Mock with Alamofire

1. Create a Custom URLProtocol

@tengfoung
tengfoung / MockURLProtocol.md
Last active May 22, 2025 00:04
MockURLProtocol

Dynamic API Mock Environment in Swift with Alamofire

This guide shows how to create a dynamic API mock environment in Swift using Alamofire. You can intercept and respond to requests using a custom URLProtocol, allowing you to return mock data instead of making real network calls — ideal for testing or development.


✅ Steps to Implement a Dynamic API Mock with Alamofire

1. Create a Custom URLProtocol

struct StickySegmentedScrollViewDynamicDemo: View {
var body: some View {
StickySegmentedScrollViewDynamic(tabs: [
TabInfo(title: "Tab One", imageName: "video_cover_1") {
ForEach(0..<10) { i in
Text("Tab 1 - Item \(i)")
.frame(maxWidth: .infinity)
.padding()
.background(Color.red.opacity(0.1))
.cornerRadius(8)
import SwiftUI
// MARK: - Tab Info
struct TabInfo<Content: View>: Identifiable {
let id = UUID()
let title: String
let imageName: String
let content: Content
}
@tengfoung
tengfoung / MD5Checksum.swift
Created January 8, 2025 04:46
Generate MD5 checksum on a folder with swift
import Foundation
import CryptoKit // Requires iOS 13.0 or later
/// Computes the MD5 checksum for a folder by hashing the contents of each file, including files in subdirectories.
///
/// - Parameter folderURL: The URL of the folder.
/// - Returns: An MD5 checksum as a hexadecimal string, or `nil` if there was an error.
func generateMD5Checksum(for folderURL: URL) -> String? {
let fileManager = FileManager.default
var combinedHash = Data()