Skip to content

Instantly share code, notes, and snippets.

View amine2233's full-sized avatar

Amine Bensalah amine2233

View GitHub Profile
@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 {
@fxm90
fxm90 / swiftui.stencil
Last active May 2, 2022 04:00
A stencil template for generating SwiftUI assets with SwiftGen. Currently only `Image` and `Color` are supported.
//
// Do not edit! File generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
//
// SwiftUI Template by Felix Mau – https://felix.hamburg
//
// Latest version available at https://gist.github.com/fxm90/d1eb5439ad0f45d727bdb98132e933a6
//
import SwiftUI
@gdavis
gdavis / assignNoRetain.swift
Created February 10, 2021 18:03
Combine assign method without the memory leak
extension Publisher where Self.Failure == Never {
public func assignNoRetain<Root>(to keyPath: ReferenceWritableKeyPath<Root, Self.Output>, on object: Root) -> AnyCancellable where Root: AnyObject {
sink { [weak object] (value) in
object?[keyPath: keyPath] = value
}
}
}
extension Result {
func tryMap<T>(_ transform:(Success) throws -> T) -> Result<T, Swift.Error> {
switch self {
case let .success(success):
do {
return .success(try transform(success))
} catch {
return .failure(error)
}
case let .failure(failure):
@ytyubox
ytyubox / MustInjected.swift
Created December 19, 2020 11:43
@MustInjected replace var:!
@propertyWrapper struct MustInjected<Value> {
private var _value: Value! = nil
#if DEBUG
let line: UInt
let file: StaticString
#endif
@available(*, unavailable)
init(wrappedValue: @autoclosure @escaping () -> Value) {
self._value = nil
line = #line