Skip to content

Instantly share code, notes, and snippets.

@kylebshr
kylebshr / ConditionalDefaultEntity.swift
Last active February 10, 2025 21:48
How to conditionally build widget configuration parameters based on UserDefaults or other conditions
//
// ConditionalDefaultEntity.swift
// Mercury
//
// Created by Kyle Bashour on 2/10/25.
// Copyright © 2025 Kyle Bashour. All rights reserved.
//
import AppIntents
@kylebshr
kylebshr / StackedHeaderCompositionalLayout.swift
Created November 9, 2023 20:51
UICollectionViewCompositionalLayout subclass that can stack a pinned collection-level header with pinned section-level headers.
class StackedHeaderCompositionalLayout: UICollectionViewCompositionalLayout {
let collectionHeaderKind: String
let sectionHeaderKind: String
init(
section: NSCollectionLayoutSection,
configuration: UICollectionViewCompositionalLayoutConfiguration,
collectionHeaderKind: String,
sectionHeaderKind: String
) {
//
// StandByMargins.swift
//
// Created by Kyle Bashour on 8/29/23.
//
import SwiftUI
extension View {
func standByMargins() -> some View {
@kylebshr
kylebshr / WidgetBackground.swift
Last active June 6, 2023 00:18
Use the new `containerBackground` modifier for widgets if iOS 17 is available, or easily fallback to a `ZStack` with standard padding.
//
// WidgetBackground.swift
//
// Created by Kyle Bashour on 6/5/23.
//
import SwiftUI
struct WidgetBackground<Background: View>: ViewModifier {
private let background: Background
//
// ContentView.swift
// SafeArea
//
// Created by Kyle Bashour on 5/24/23.
//
import SwiftUI
struct ContentView: View {
class ViewController: UIViewController {
let left = ScrollViewController()
let right = ScrollViewController()
override func viewDidLoad() {
super.viewDidLoad()
for child in [left, right] {
addChild(child)
@kylebshr
kylebshr / ViewController.swift
Last active June 7, 2021 23:36
UISheetPresentationController
//
// ViewController.swift
// Sheets
//
// Created by Kyle Bashour on 6/7/21.
//
import UIKit
class ViewController: UIViewController, UISheetPresentationControllerDelegate {
protocol MyProtocol {}
struct MyImplemention: MyProtocol {}
struct MyStruct {
func emptyView() -> some MyProtocol {
MyImplemention()
}
@kylebshr
kylebshr / FailedDecoding.swift
Last active May 29, 2020 06:40
Can't figure out why this doesn't decode??
import Foundation
struct PlaidBalance: Codable {
var current: Decimal
var available: Decimal
var isoCurrencyCode: String
}
struct PlaidAccount: Codable {
enum AccountType: String, Codable {
//
// ViewController.swift
// Table
//
// Created by Kyle Bashour on 1/21/20.
// Copyright © 2020 Kyle Bashour. All rights reserved.
//
import UIKit