Skip to content

Instantly share code, notes, and snippets.

View kylehughes's full-sized avatar
🐶
Updog

Kyle Hughes kylehughes

🐶
Updog
View GitHub Profile
import Foundation
import ReactiveCocoa
//: # Backoff
//: ## Retry with backoff operator
extension SignalProducerType {
func retryWithBackoff<S: SequenceType where S.Generator.Element == NSTimeInterval>(strategy: S) -> SignalProducer<Value, Error> {
var generator = strategy.generate()
@larsaugustin
larsaugustin / ExampleView.swift
Created August 19, 2020 16:59
Conditional view modifiers in SwiftUI
struct ExampleView: View {
var body: some View {
Text("Example")
.if(true) { $0.foregroundColor(.red) }
}
}
@b3ll
b3ll / BlurryVibrantView.swift
Created November 10, 2019 07:15
iOS SwiftUI Blurry Vibrant Container View
//
// BlurryVibrantView.swift
//
//
// Created by Adam Bell on 11/9/19.
// Copyright © 2019 Adam Bell. All rights reserved.
//
import SwiftUI
import UIKit
@layoutSubviews
layoutSubviews / CombineLatestRace.swift
Created February 1, 2021 22:05
Gist demonstrating Publishers.CombineLatest is racy
func testCombineLatest() {
for _ in 1...100 {
let e = expectation(description: "Each subject should emit true")
let s1 = CurrentValueSubject<Bool, Never>(false)
let s2 = CurrentValueSubject<Bool, Never>(false)
let cancellable = Publishers.CombineLatest(s1, s2)
.sink {
if $0, $1 {
e.fulfill()
}
import UIKit
import Accelerate
enum Dither {
case jjn
case atkinson
}
enum Desaturate {
case mono
import SwiftUI
struct ContentView: View {
static var toggle = false
static let settings: [Setting] = [
.push(
label: "Embedded content",
[
.text(label: "Deeper!", "Here is some embedded informational text")
]
@DenTelezhkin
DenTelezhkin / StateWrappedView.swift
Created September 23, 2020 14:01
StateObject alternative on iOS 13 / macOS Catalina
import SwiftUI
protocol ViewModelContainable: View {
associatedtype ViewModel : ObservableObject
init(model: ViewModel)
}
// This struct is a direct MVVM alternative to @StateObject in iOS 14 and Mac OS Big Sur.
@jazzychad
jazzychad / UIDebouncedColorWell.swift
Created September 11, 2021 00:23
A better way to get color values from UIColorWells
//
// UIDebouncedColorWell.swift
//
import UIKit
import Combine
private class PublishingColor {
@Published var color: UIColor? = nil
}
@CodeSlicing
CodeSlicing / GeometryReaderStack.swift
Last active October 8, 2021 09:22
A version of GeometryReader that behaves like a greedy ZStack with a default alignment of center.
//
// GeometryReaderStack.swift
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
@ShihabM
ShihabM / AppDelegate.gist
Created November 3, 2021 09:53
Dock Shooter - a game in your dock icon
//
// AppDelegate.swift
// Dock Shooter
//
// Created by Shihab Mehboob on 01/11/2021.
//
import Cocoa
@main