Skip to content

Instantly share code, notes, and snippets.

View omidgolparvar's full-sized avatar

Omid Golparvar omidgolparvar

View GitHub Profile
protocol ThumbnailProvider<Input> {
associatedtype Input
@MainActor
func makeThumbnail(for input: Input, ofSize size: CGSize) async -> UIImage?
@MainActor
func makeThumbnailSync(for input: Input, ofSize size: CGSize) -> UIImage?
}
let underReviewFlag_1 = ProcessInfo.processInfo.environment["CFNETWORK_DIAGNOSTICS"] != nil
let underReviewFlag_2 = ProcessInfo.processInfo.environment["CFNETWORK_HAR_LOGGING"] != nil
@omidgolparvar
omidgolparvar / ios-test-custom-appdelegate.swift
Created September 26, 2025 14:20
Custom AppDelegate for Tests
/// https://www.linkedin.com/posts/jacobmartinbartlett_advanced-ios-testing-speed-up-your-tests-activity-7375121681171849216-2gSg
import UIKit
private func isRunningUnitTests() -> Bool {
NSClassFromString("Testing.Test") != nil ||
ProcessInfo.processInfo.environment["XCTestBundlePath"] != nil
}
let appDelegateClass: AnyClass = if isRunningUnitTests() {
@omidgolparvar
omidgolparvar / SecureView.swift
Last active October 10, 2025 14:20
A view protects content from screenshots and screen recordings.
/// This file is based on the original source code from:
/// https://github.com/kuttz/SecureYourView
/// Some modifications have been made to adapt it for our use case.
import Foundation
import UIKit
import Combine
/// This custom view is designed to protect its content against screenshots
/// and screen recordings, ensuring that sensitive information cannot be
/// https://www.swiftbysundell.com/articles/let-vs-var-for-swift-struct-properties/
@propertyWrapper struct Readonly<Value> {
let wrappedValue: Value
}
extension Readonly: Encodable where Value: Encodable {
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(wrappedValue)
// A protocol with a single `@MainActor` method.
protocol DataStoring {
@MainActor func save()
}
// A struct that does not conform to the protocol.
struct DataStore1 { }
// When we make it conform and add save() at the same time, our method is implicitly @MainActor.
struct Output {
let string: StringBuilder.Component
}
@resultBuilder
struct StringBuilder {
/// The type of individual statement expressions in the transformed function,
protocol Flow: Equatable {
func isEqual(to value: Self) -> Bool
}
enum Flows {}
extension Flows {
struct FlowOne: Flow, CustomStringConvertible {
let name: String
/// https://www.donnywals.com/swift-concurrencys-taskgroup-explained/
///
/// When an error is thrown from the closure provided to withThrowingTaskGroup, the task group will fail with that error.
/// Before this error is thrown, the task group will mark any unfinished tasks as cancelled to allow them to stop
/// executing work as soon as possible in order to comply with Swift Concurrency's cooperative cancellation.
/// Once all tasks have completed (either by finishing their work or throwing an error), the task group will throw its error and complete.
///
/// ...
///
extension SymmetricKey {
// MARK: Custom Initializers
/// Creates a `SymmetricKey` from a Base64-encoded `String`.
///
/// - Parameter base64EncodedString: The Base64-encoded string from which to generate the `SymmetricKey`.
init?(base64EncodedString: String) {
guard let data = Data(base64Encoded: base64EncodedString) else {
return nil