Skip to content

Instantly share code, notes, and snippets.

@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
@kylebshr
kylebshr / VaporSignInWithAppleJWT.swift
Last active August 1, 2022 12:26
Verifying a Sign in with Apple JWT in Vapor 3
/*
Once you've signed in with Apple in your iOS app, turn the `identityToken` into a string with something like
`String(data: identityToken, encoding: .utf8)`. Then use that string in the Authorization header:
`urlRequest.addValue("Bearer \(identityString)", forHTTPHeaderField: "Authorization")`
*/
import Vapor
import JWT