Contact

Currently building at the Recurse Center

Thu Dec 05 2024

What I did yesterday

Back on track with SwiftUI! Worked up to day 87 of 100 Days of SwiftUI.

func addNotification(for prospect: Prospect) {
        let center = UNUserNotificationCenter.current()
        
        let addRequest = {
            let content = UNMutableNotificationContent()
            content.title = "Contact \(prospect.name)"
            content.subtitle = prospect.emailAddress
            content.sound = UNNotificationSound.default
            
            // var dateComponents = DateComponents()
            // dateComponents.hour = 9
//            let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
            let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false) \\ using this for testing sake
            
            let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
            center.add(request)
        }
        
        center.getNotificationSettings { settings in
            if settings.authorizationStatus == .authorized {
                addRequest()
            } else {
                center.requestAuthorization(options: [.alert, .badge, .sound]) { success, error in
                    if success {
                        addRequest()
                    } else if let error {
                        print(error.localizedDescription)
                    }
                }
            }
        }
    }
struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello, World!")
                .onTapGesture {
                    print("Text tapped")
                }
        }
        .onTapGesture {
            print("VStack tapped")
        }
    }
}

In this situation SwiftUI will always give the child’s gesture priority, which means when you tap the text view above you’ll see “Text tapped”. We can get around this by doing one of two things:

  1. Assign priority to the second tap gesture:
.highPriorityGesture(
            TapGesture()
                .onEnded {
                    print("VStack tapped")
                }
        )
  1. Tell SwiftUI to trigger both simultaneously
.simultaneousGesture(
            TapGesture()
                .onEnded {
                    print("VStack tapped")
                }
        )
   .swipeActions {
        Button("Delete", systemImage: "trash", role: .destructive) {
            modelContext.delete(prospect)
        }
        ... // omitted for brevity
   }

Simple as that

Today

As I near the end of my RC batch I really am starting to get RC’s term “Never Graduate” because this way of learning has really become a part of me and the more I learn at this pace the more I feel I have to share it. Love it. Shoutout to the faculty and everyone who’s made RC possible!

Upcoming