Skip to content

Instantly share code, notes, and snippets.

View StewartLynch's full-sized avatar

Stewart Lynch StewartLynch

View GitHub Profile
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
@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 / 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")