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 Binding { | |
/// Binding to an optional value by providing a defatult value. | |
/// | |
/// example | |
/// | |
/// struct Sample: View { | |
/// @Binding var name: String? | |
/// |
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 <#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#>) -> () |
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", |
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 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
{ | |
"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 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
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
struct CustomHeightSheet: View { | |
@State private var modalSheetType: ModalSheetType? | |
var body: some View { | |
NavigationStack { | |
VStack { | |
HStack { | |
Button { | |
modalSheetType = .smaller(200) | |
} label: { | |
Text("Small Sheet") |
NewerOlder