Skip to content

Instantly share code, notes, and snippets.

View amine2233's full-sized avatar

Amine Bensalah amine2233

View GitHub Profile
@IanKeen
IanKeen / DynamicProperties.swift
Created February 19, 2025 19:16
Support stored properties in extensions
public protocol DynamicProperties: AnyObject {
subscript<T>(dynamic key: String) -> T? { get set }
}
private extension String {
var unsafePointer: UnsafeRawPointer {
return UnsafeRawPointer(bitPattern: hashValue)!
}
}
extension DynamicProperties {
@IanKeen
IanKeen / ObservableAppStorage.swift
Created October 10, 2024 17:06
PropertyWrapper: ObservableAppStorage - Make UserDefaults work with @observable models (without all the boilerplate)
import Observation
public protocol _Observable: Observable {
nonisolated
func _access<Member>(keyPath: KeyPath<Self, Member>)
nonisolated
func _withMutation<Member, MutationResult>(
keyPath: KeyPath<Self, Member>,
_ mutation: () throws -> MutationResult
@ole
ole / swift-has-feature.sh
Last active April 12, 2025 11:59
swift-list-features: List Swift compiler upcoming and experimental feature flags. · swift-has-feature: Check if a given compiler knows a specific feature flag, and whether it's an upcoming or experimental flag.
#!/bin/zsh
# Test if the Swift compiler knows about a particular language feature.
#
# Usage:
#
# swift-has-feature [--swift SWIFT_PATH] [--language-version LANGUAGE_VERSION] FEATURE
#
# The feature should be an upcoming or experimental language feature,
# such as `"StrictConcurrency"` or `"ExistentialAny"`.
@alessio
alessio / Homebrew in a multi-user environment.md
Created January 13, 2024 22:13 — forked from claui/Homebrew in a multi-user environment.md
Using Homebrew on macOS in a multi-user environment

I’ve had success using Homebrew in a multi-user environment the following way:

Create a shared Homebrew user

Create a new (non-GUI) user, group and home directory:

sudo /usr/sbin/sysadminctl -addUser brew \
  -fullName 'Homebrew' -admin -home /var/brew \
  -password - -UID 430 \
@EvolverSwiftUI
EvolverSwiftUI / SignInWithAppleHelper.swift
Created March 25, 2023 12:04 — forked from SwiftfulThinking/SignInWithAppleHelper.swift
Sign In With Apple for iOS (async support)
import Foundation
import CryptoKit
import AuthenticationServices
import UIKit
struct SignInWithAppleResult {
let token: String
let nonce: String
}
import SwiftUI
import Combine
struct ContentView: View {
@State var items: [Int] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var body: some View {
List {
ForEach(items, id: \.self) { item in
Text("Item: \(item)")
@lotusirous
lotusirous / dropdown.swift
Created December 1, 2022 07:23
A elegant solution dropdown menu for SwiftUI
//
// ContentView.swift
// WeirdSheet
//
// Created by lotusirous on 28/11/2022.
//
import SwiftUI
protocol Nameable {
@nikitamounier
nikitamounier / FrenchTCA.md
Last active April 6, 2023 08:27
A French translation of The Composable Architecture's README.md

The Composable Architecture

CI

The Composable Architecture (TCA, pour faire court) est une bibliothèque permettant de construire des applications de manière cohérente et compréhensible, en tenant compte de la composition, des tests et de l'ergonomie. Elle peut être utilisée avec SwiftUI, UIKit, et encore, et sur toutes les plateformes Apple (iOS, ma

@JenssRey
JenssRey / UIViewController+SwiftUI.swift
Created June 25, 2021 08:54
UIViewController extension for adding a SwiftUI View
import UIKit
import SwiftUI
// Credits to: https://www.avanderlee.com/swiftui/integrating-swiftui-with-uikit/
extension UIViewController {
/// Add a SwiftUI `View` as a child of the input `UIView`.
/// - Parameters:
/// - swiftUIView: The SwiftUI `View` to add as a child.
import CloudKit
import Combine
/// Fetches the user's CloudKit Account status.
///
/// - Parameter container: The container to check the status in.
///
/// - Returns: A deferred future that resolves to the user's CloudKit Account status.
func getAccountStatus(for container: CKContainer) -> AnyPublisher<CKAccountStatus, Error> {
Deferred {