Skip to content

Instantly share code, notes, and snippets.

View kylehughes's full-sized avatar
🐶
Updog

Kyle Hughes kylehughes

🐶
Updog
View GitHub Profile
@defagos
defagos / ExampleView.swift
Created September 28, 2021 21:04
Send a message to the UIKit responder chain from a SwiftUI view
@objc protocol ExampleActions: AnyObject {
func pushUIKitViewController()
}
struct ExampleView: View {
@FirstResponder private var firstResponder
var body: some View {
Button {
firstResponder.sendAction(#selector(ExampleActions.pushUIKitViewController))
@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
}
// Bigger iPhones = any Max, any Plus, iPhone XR, iPhone 11
switch (UITraitCollection.current.horizontalSizeClass, UITraitCollection.current.verticalSizeClass) {
case (.compact, .compact):
// Smaller iPhones in landscape
case (.compact, .regular):
// iPhones in portrait
// iPads in portrait during any split screen,
@Iron-Ham
Iron-Ham / Wrappers.swift
Last active March 22, 2023 14:30
Use property wrappers to ignore a variable for synthesized `Equatable` and `Hashable`.
import Foundation
@propertyWrapper
struct IgnoreEquatable<Wrapped>: Equatable {
var wrappedValue: Wrapped
static func == (lhs: IgnoreEquatable<Wrapped>, rhs: IgnoreEquatable<Wrapped>) -> Bool {
true
}
}
@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:
//
@kylehughes
kylehughes / HapticFeedback.swift
Last active May 17, 2022 15:46
Convenient Swift abstractions for generating haptic feedback on iOS.
// Copyright 2021 Kyle Hughes
//
// 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:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.
//
@IanKeen
IanKeen / View+Relative.swift
Last active January 16, 2023 13:03
SwiftUI relative frame
extension View {
func relative(width: CGFloat? = nil, height: CGFloat? = nil, alignment: Alignment = .center) -> some View {
Color.clear
.frame(maxWidth: width.map { _ in .infinity }, maxHeight: height.map { _ in .infinity })
.overlay(GeometryReader { proxy in
ZStack {
self.frame(
width: width.map { proxy.size.width * $0 },
height: height.map { proxy.size.height * $0 }
)
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")
]
@noahsark769
noahsark769 / UserDefaultsWrappers.swift
Created May 14, 2021 18:20
User Defaults Property Wrappers
import Foundation
@propertyWrapper
struct SimpleUserDefault<T> {
let userDefaults: UserDefaults
let key: String
let defaultValue: T
init(
userDefaults: UserDefaults = UserDefaults.standard,
@insidegui
insidegui / statusbarfix.sh
Created March 16, 2021 23:04
Alias called "statusbarfix" which will update the status bar on any iOS Simulator that's currently running to look better for marketing images
alias statusbarfix='xcrun simctl status_bar booted override --time 9:41 --cellularMode active --cellularBars 4 --batteryState charging --operatorName ""'