Ok, actually, the error is that the 'items' is not in the scope of the function.
ForEach(items, id: \.self) { item in
OneTimeRow(meeting: item)
}
.onDelete(perform: deleteItems, removeSingleNotification(meetingID: "\(item.meetingLink)"))
Any ideas about how to pass the specific item to the function? Thanks.
Post
Replies
Boosts
Views
Activity
Yes, I tried:
.onDelete(perform: deleteItems, removeSingleNotification(meetingID: "\(item.meetingLink)"))
But it's giving me a "cannot type check in reasonable time" error.
Thank you, I'm now having trouble because I want to use the .onDelete(perform: ) to call two functions, the actual delete function then the delete notification function. I don't know how to call two functions, though:
.onDelete(perform: deleteItems)
Here are my two functions:
private func deleteItems(offsets: IndexSet) {
withAnimation {
offsets.map { items[$0] }.forEach(viewContext.delete)
do {
try viewContext.save()
} catch {
print("There was an error deleting items")
}
}
}
private func removeSingleNotification(meetingID: String) {
notificationManager.removePendingNotificationRequests(meetingID: meetingID)
}
So I want to call both of these with the onDelete but I don't know how to include both functions because when I do, I get a compiler error that it can't type check in a reasonable amount of time. Thank you.
Anyone have any ideas? Basically, I need a way to pass the meeting name of the meeting that is being deleted to the delete function.
ForEach(items, id: \.self) { item in
OneTimeRow(meeting: item)}
.onDelete(perform: deleteItems)
I'm going to include the following in the delete function:
removePendingNotificationRequests(withIdentifiers identifiers: [String]
Any thoughts?
I figured it out. For anyone wondering, I did
let data = audioURL
Text statement is correct - doesn't compile even with static string. Code is below:
import SwiftUI
import Foundation
struct OneTimeRow: View {
@Environment(\.openURL) var openURL
var oneTimeName: String
var oneTimeLink: String?
var oneTimeDate: Date
var oneTimeNotes: String?
var body: some View {
HStack {
VStack(alignment: .leading){
Text("\(oneTimeName)")
.font(.title3)
.fontWeight(.semibold)
.padding(.top, 5.0)
.padding(.bottom, 0)
if isDateInToday(oneTimeDate) {
Text("Today at \(oneTimeDate, formatter: itemFormatter)")
} else if isDateinYesterday(oneTimeDate){
Text("Yesterday at \(oneTimeDate, formatter: itemFormatter)")
} else if isDateInTomorrow(oneTimeDate) {
Text("Tomorrow at \(oneTimeDate, formatter: itemFormatter)")
} else {
Text("\(oneTimeDate, formatter: showDayFormatter) at \(oneTimeDate, formatter: itemFormatter)")
.foregroundColor(Color.gray)
.padding(.bottom, 3.0)
.padding(.top, -3)
}
}
Spacer()
Button {
print("Sending to computer")
guard let data = URL(string: "\(oneTimeLink ?? "undefined")") else { return }
let av = UIActivityViewController(activityItems: [data], applicationActivities: nil)
UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)
} label: {
Image(systemName: "wave.3.right.circle.fill")
.font(.title)
.padding(.trailing, 1)
}
.buttonStyle(BorderlessButtonStyle())
Button {
print("Joining on iPhone")
openURL(URL(string: "\(oneTimeLink ?? "untitled")")!)
} label: {
Text("JOIN")
.fontWeight(.semibold)
.foregroundColor(Color.white)
.frame(width: 60.0, height: 30.0)
.padding(.trailing, 1.0)
.background(/*@START_MENU_TOKEN@*//*@PLACEHOLDER=View@*/Color.blue/*@END_MENU_TOKEN@*/)
.cornerRadius(20.0)
}
.buttonStyle(BorderlessButtonStyle())
NavigationLink(destination: MeetingsDetailView(detailMeetingName: "\(oneTimeName)", detailMeetingLink: "\(oneTimeLink ?? "Undefined")", detailMeetingTime: oneTimeDate, detailMeetingNotes: "\(oneTimeNotes ?? "No notes")")) {
}
.frame(width: 10)
}
}
}
private let itemFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.timeStyle = .short
return formatter
}()
private let showDayFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .short
return formatter
}()
Ok, I've imported Foundation, but I'm still getting a compiler error: "Cannot find 'isDateInToday' in scope". I've cleaned the build folder and attempted to build.
My code:
if isDateInToday(oneTimeDate) {
Text("Today at \(oneTimeDate, formatter: itemFormatter)")
oneTimeDate is a variable of type date.
Thank you, so now I have something like this
var meeting: Meeting
But the PreviewProvider now says it is missing an argument for the parameter 'meetings'. How do I initialize some dummy data for the preview if the data is in CoreData?
I have 'meetingName' of type string, 'meetingLink' of type URI, and 'meetingTime' of type Date.
Thank you!
Wow, that fixed it. Thank you so much! As a new developer this is absolutely mindblowing.