Skip to content

Instantly share code, notes, and snippets.

View JoshHrach's full-sized avatar
🏠
Working from home

Josh Hrach JoshHrach

🏠
Working from home
View GitHub Profile
@JoshHrach
JoshHrach / DemoView.swift
Created January 16, 2024 00:48
UIViewRepresentable Sample Code
struct ThirdPartyDemoView: View {
@State private var shouldAdd = true
@State private var currentValue = 0
var body: some View {
ThirdPartyReader { proxy in
Text("\(currentValue)")
ThirdPartyView(shouldAdd: shouldAdd)
.viewChangedValueTo { view, newValue in
currentValue = newValue
@JoshHrach
JoshHrach / ContentView.swift
Created December 1, 2020 19:01
NavigationLink bug
struct ContentView: View {
var body: some View {
NavigationView {
List {
NavigationLink(destination: Text("Top Level")) {
Text("Top Level Link")
}
NavigationLink(destination: detailView) {
Text("Show Sub Links")
@JoshHrach
JoshHrach / gist:990b784b661de63485670cfda32a9e10
Last active April 28, 2020 23:56
Simple Binding example
struct NameDisplayView: View {
@State var name: String = "unknown"
@State var showNameChange = false
var body: some View {
VStack {
Text("Your name is \(name)")
Divider()
Button("Change") {
self.showNameChange = true
@JoshHrach
JoshHrach / PropertyWrappers.swift
Created April 9, 2020 01:14
Sample Property Wrappers
@propertyWrapper
/// Wrapper used to easily encode a `Date` to and decode a `Date` from an ISO 8601 formatted date string.
struct ISO8601Date: Codable {
var wrappedValue: Date
init(wrappedValue: Date) {
self.wrappedValue = wrappedValue
}
init(from decoder: Decoder) throws {