Skip to content

Instantly share code, notes, and snippets.

View StewartLynch's full-sized avatar

Stewart Lynch StewartLynch

View GitHub Profile
@StewartLynch
StewartLynch / seed.txt
Created February 3, 2026 22:19
SQLiteData Gist for seeding Person table
try db.seed {
Person(id: UUID(0), name: "Mom", notes: "Likes gardening and cooking")
Person(id: UUID(1), name: "Dad", birthDate: formatter.date(from: "1968-11-03"), notes: "Enjoys golf and reading")
Person(id: UUID(2), name: "Sarah", notes: "Sister - loves art supplies")
Person(id: UUID(3), name: "Grandma", birthDate: formatter.date(from: "1942-02-21"), notes: "Knitting and classic movies")
Person(id: UUID(4), name: "Grandpa", notes: "Fishing trips on weekends")
Person(id: UUID(5), name: "Uncle Joe", birthDate: formatter.date(from: "1975-07-08"), notes: "BBQ master")
Person(id: UUID(6), name: "Aunt Lisa", notes: "Yoga and photography")
Person(id: UUID(7), name: "Cousin Mike", birthDate: formatter.date(from: "2001-09-14"), notes: "Video games and sneakers")
Person(id: UUID(8), name: "Emma", birthDate: formatter.date(from: "1992-03-30"), notes: "Co-worker - coffee enthusiast")
@StewartLynch
StewartLynch / DateOffset.swift
Created January 6, 2026 00:02
Date Offset Extension
import Foundation
extension Date {
/// Returns a date that is `offset` days from this date.
/// - Parameter offset: The number of days to add or subtract from `self`.
/// - Returns: A new `Date` `offset` days days before or after `self`.
func offset(_ offset: Int) -> Date {
Calendar.current.date(byAdding: .day, value: offset, to: self)!
}
}
import SwiftUI
extension Binding {
/// Binding to an optional value by providing a defatult value.
///
/// example
///
/// struct Sample: View {
/// @Binding var name: String?
///
import SwiftUI
struct <#ViewName#>: View, OverTopable {
let title: String
let choices: [<#Type#>]
let current: <#Type#>
@State var updatedContent: <#Type#>
let hasTwoButtons: Bool
@Binding var showOverTop: Bool
var update: (<#Type#>) -> ()
@StewartLynch
StewartLynch / RemoveMoreButton.swift
Created January 29, 2025 21:20
Remove More Button from TabView
import SwiftUI
// KavSoft Solution for removing More Button for Tab Bar SwiftUI
// https://www.youtube.com/watch?v=zSHBePAXJCs
struct RemoveMoreButton: UIViewRepresentable {
var result: () -> ()
func makeUIView(context: Context) -> UIView {
let view = UIView(frame: .zero)
@StewartLynch
StewartLynch / HelpType+extension.swift
Last active January 22, 2025 22:20
HelpType Extension for video on Custom Help
import SwiftUI
extension HelpType {
var pages: [HelpPage] {
switch self {
case .peopleList:
[
HelpPage(
image: Image(systemName: "person.3.fill"),
title: "Person List",
import SwiftData
import SwiftUI
struct MockData: PreviewModifier {
func body(content: Content, context: ModelContainer) -> some View {
content
.modelContainer(context)
}
static func makeSharedContext() async throws -> ModelContainer {
let container = try! ModelContainer(
@StewartLynch
StewartLynch / Widget Snippet.txt
Created September 25, 2024 19:54
Sample Widget Template Snippet
import WidgetKit
import SwiftUI
// MARK: - Entry Data Model
struct <#WidgetName#>: TimelineEntry {
let date: Date
// Add any additional data you need for your widget
}
@StewartLynch
StewartLynch / mockData.json
Created September 14, 2024 20:12
JSON for SwiftData Updates
{
"genres": [
{
"name" : "Fantasy",
"color" : "#B33234"
},
{
"name" : "Science Fiction",
"color" : "#FFC300"
@StewartLynch
StewartLynch / GlobalSheet.swift
Last active August 16, 2024 04:11
Global Sheets. Orginal idea via Mohammad Azam https://www.youtube.com/watch?v=mj2cRsvYH44 but modified to use a sheet conforming to View, a View Modifier and the new @entry macro
import SwiftUI
enum Sheet: Identifiable, View { // Remove Hashabke but add View conformance
case settings
case contact(String)
case nameEntry(Binding<String>)
var id: String {String(describing: self)} // Now Sheet does not have to conform to Hashable
var body: some View { // Now that you have View, you have a body