This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DATE ___DATE___ | |
// TIME ___TIME___ | |
// YEAR ___YEAR___ | |
// --------------------------------- | |
// DEFAULTTOOLCHAINSWIFTVERSION ___DEFAULTTOOLCHAINSWIFTVERSION___ | |
// RUNNINGMACOSVERSION ___RUNNINGMACOSVERSION___ | |
// --------------------------------- | |
// FILEBASENAME ___FILEBASENAME___ | |
// FILEBASENAMEASIDENTIFIER ___FILEBASENAMEASIDENTIFIER___ | |
// FILENAME ___FILENAME___ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FirstOnAppearModifier: ViewModifier { | |
@State private var hasPerformedAction = false | |
let action: (() -> Void)? | |
func body(content: Content) -> some View { | |
content | |
.onAppear { | |
if !hasPerformedAction { | |
hasPerformedAction = true | |
action?() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CustomHeightSheet: View { | |
@State private var modalSheetType: ModalSheetType? | |
var body: some View { | |
NavigationStack { | |
VStack { | |
HStack { | |
Button { | |
modalSheetType = .smaller(200) | |
} label: { | |
Text("Small Sheet") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"genres": [ | |
{ | |
"name" : "Fantasy", | |
"color" : "#B33234" | |
}, | |
{ | |
"name" : "Science Fiction", | |
"color" : "#FFC300" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WidgetKit | |
import SwiftUI | |
// MARK: - Entry Data Model | |
struct <#WidgetName#>: TimelineEntry { | |
let date: Date | |
// Add any additional data you need for your widget | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
extension HelpType { | |
var pages: [HelpPage] { | |
switch self { | |
case .peopleList: | |
[ | |
HelpPage( | |
image: Image(systemName: "person.3.fill"), | |
title: "Person List", |