Skip to content

Instantly share code, notes, and snippets.

View Gujci's full-sized avatar

Máté Gujgiczer Gujci

  • Disney+ Hotstar
  • Budapest, Hungary
View GitHub Profile
@Gujci
Gujci / StripePaymentCardTextField.swift
Created July 2, 2020 08:57
SwiftUI wrapper around the STPPaymentCardTextField from Stripe
struct StripePaymentCardTextField: UIViewRepresentable {
@Binding var cardParams: STPPaymentMethodCardParams
@Binding var isValid: Bool
func makeUIView(context: Context) -> STPPaymentCardTextField {
let input = STPPaymentCardTextField()
input.borderWidth = 0
input.delegate = context.coordinator
return input
@Gujci
Gujci / ListKey.swift
Last active March 9, 2021 14:12
Wrapper to bridge realms auto updating behaviour with SwiftUIs value based immutability requirement. (Extract from https://stackoverflow.com/questions/57160790/index-out-of-bounds-when-using-realm-with-swiftui)
import RealmSwift
typealias Model = Object & Identifiable
struct ListKey<T: Model>: Identifiable {
let id: T.ID
}
extension Results where Element: Model {
@Gujci
Gujci / Pager.swift
Created October 15, 2019 08:50
Basic `PageControl` in SwiftUI without any UIKit components.
struct PageControl: View {
var numberOfPages: Int
@Binding var currentPage: Int
var body: some View {
HStack {
ForEach(0..<numberOfPages) { index in
Circle()
import SwiftUI
extension String: Identifiable {
public var id: String { self }
}
struct ContentView: View {
@State private var baseNumber = ""
@State private var dimensionSelection: String = ""
@Gujci
Gujci / Grid.swift
Last active October 14, 2019 15:24
Simple grid implementation based on the `ForEach` and `Stack` interfaces
struct Grid<Data: RandomAccessCollection, Content: View>: View, DynamicViewContent where Data.Index == Int {
public var data: Data
public var colCount: Int
public var alignment: HorizontalAlignment
public var spacing: CGFloat
impost SwiftUI
struct TactileSliderView: UIViewRepresentable {
@Binding var value: Float
func makeUIView(context: Context) -> TactileSlider {
let slider = TactileSlider()
slider.setValue(value, animated: false)
slider.addTarget(context.coordinator, action: #selector(context.coordinator.valueChanged), for: .valueChanged)
@Gujci
Gujci / CustomTextField.swift
Last active November 16, 2022 17:42
Simple snippet how to disable actions in a UITextField
import UIKit
@IBDesignable
class CustomTextField: UITextField {
@IBInspectable var isPasteEnabled: Bool = true
@IBInspectable var isSelectEnabled: Bool = true
@IBInspectable var isSelectAllEnabled: Bool = true
@Gujci
Gujci / waterfall.swift
Last active May 16, 2023 08:52
swift implementation of the famous async-waterfall
public class Async {
/// Throw version implementation of waterfall
///
/// - Parameters:
/// - initialValue: initial passed value of the chain
/// - chain: chain of closures to process
/// - end: last callback. Called after the chain finished or in an error occures
/// - Throws: Any error that one of the chain elements throwed
public protocol OptionalValueObservable {
var isComplete: Bool {get}
var hasAnyProperty: Bool {get}
}
public extension OptionalValueObservable {
var isComplete: Bool {
get {
return Mirror(reflecting: self).children.reduce(true) { acc, val in
let subMirror = Mirror(reflecting: val.value)