Skip to content

Instantly share code, notes, and snippets.

View StewartLynch's full-sized avatar

Stewart Lynch StewartLynch

View GitHub Profile
@StewartLynch
StewartLynch / FiLEHEADER_Macros.txt
Last active July 29, 2024 21:32
Xcode Fileheader Macros
// DATE ___DATE___
// TIME ___TIME___
// YEAR ___YEAR___
// ---------------------------------
// DEFAULTTOOLCHAINSWIFTVERSION ___DEFAULTTOOLCHAINSWIFTVERSION___
// RUNNINGMACOSVERSION ___RUNNINGMACOSVERSION___
// ---------------------------------
// FILEBASENAME ___FILEBASENAME___
// FILEBASENAMEASIDENTIFIER ___FILEBASENAMEASIDENTIFIER___
// FILENAME ___FILENAME___
@StewartLynch
StewartLynch / firstOnAppear.swift
Created June 29, 2024 19:28
firstOnAppear View Modifier
struct FirstOnAppearModifier: ViewModifier {
@State private var hasPerformedAction = false
let action: (() -> Void)?
func body(content: Content) -> some View {
content
.onAppear {
if !hasPerformedAction {
hasPerformedAction = true
action?()
@StewartLynch
StewartLynch / CustomLabeledContentStyles.swift
Last active July 6, 2024 22:22
Custom LabeledContentStyles
struct TopAlignedLabeledContentStyle: LabeledContentStyle {
// You can design it any way you want.
func makeBody(configuration: Configuration) -> some View {
HStack(alignment: .top) {
configuration.label
Spacer()
configuration.content
.foregroundStyle(.secondary)
}
}
@StewartLynch
StewartLynch / CustomHeightSheet.swift
Created July 31, 2024 19:17
CustomHeight Sheet presentation
struct CustomHeightSheet: View {
@State private var modalSheetType: ModalSheetType?
var body: some View {
NavigationStack {
VStack {
HStack {
Button {
modalSheetType = .smaller(200)
} label: {
Text("Small Sheet")
@StewartLynch
StewartLynch / ContentView.swift
Last active August 8, 2024 00:42
App Crashes when return to Home Screen
import SwiftUI
struct ContentView: View {
@State private var selection: Int = 1
@AppStorage("MyAppTabViewCustomization") private var customization: TabViewCustomization
var body: some View {
TabView(selection: $selection) {
TabSection("Vacations") {
Tab("Planned", systemImage: "airplane", value: 1) {
Text("Planned Vacations")
@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
@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 / 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
}
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 / 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",