Post

Replies

Boosts

Views

Activity

Reply to SwiftData: Unable to delete (Xcode 16)
Here's the entire code: import SwiftData struct ChatHistory: View { @Environment(\.modelContext) var modelContext // Sort SwiftData list by DATE: @Query(sort: \SwiftDatabase.date, order: .reverse, animation: .spring) private var chatLog: [SwiftDatabase] @Environment(\.dismiss) var dismiss @State private var actTxt: String = "" @State private var btnDel = false var body: some View { PullDownToDismiss() NavigationStack { List { ForEach(chatLog) { show in HStack { // Show Date of Chat: Text("\(show.date.formatted(date: .numeric, time: .omitted))") .foregroundStyle(Color.init(uiColor: .secondaryLabel)) .font(.system(size: 18, weight: .regular)) Text("\(show.actTxt ?? "----")") .foregroundStyle(Color.init(uiColor: .label)) .font(.system(size: 22, weight: .bold)) .navigationTitle("Chat Log") .navigationBarTitleDisplayMode(.inline) .swipeActions(allowsFullSwipe: true) { Button("Delete", systemImage: "trash", role: .destructive) { } } } }.onDelete(perform: deleteLog) } } } public func deleteLog(_ indexSet: IndexSet) { for index in indexSet { let chat = chatLog[index] modelContext.delete(chat) // do { // try modelContext.save() // // } catch { // // print("Error saving: \(error)") // // } } } }
Jun ’24
Reply to SwiftUI: Extra line in NavigationStack
The 2 NavigationTitles are for the listView and then the DetaiView. The data.name is coming from an array thats in another Swift file. Its where the information is coming from. I did not know about pasting code with the Paste and Match style. I'll remember that for the next time. Here's a screen shot of the previous screen before the original one. Thanks.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’22
Reply to SwiftData: Unable to delete (Xcode 16)
Here's the entire code: import SwiftData struct ChatHistory: View { @Environment(\.modelContext) var modelContext // Sort SwiftData list by DATE: @Query(sort: \SwiftDatabase.date, order: .reverse, animation: .spring) private var chatLog: [SwiftDatabase] @Environment(\.dismiss) var dismiss @State private var actTxt: String = "" @State private var btnDel = false var body: some View { PullDownToDismiss() NavigationStack { List { ForEach(chatLog) { show in HStack { // Show Date of Chat: Text("\(show.date.formatted(date: .numeric, time: .omitted))") .foregroundStyle(Color.init(uiColor: .secondaryLabel)) .font(.system(size: 18, weight: .regular)) Text("\(show.actTxt ?? "----")") .foregroundStyle(Color.init(uiColor: .label)) .font(.system(size: 22, weight: .bold)) .navigationTitle("Chat Log") .navigationBarTitleDisplayMode(.inline) .swipeActions(allowsFullSwipe: true) { Button("Delete", systemImage: "trash", role: .destructive) { } } } }.onDelete(perform: deleteLog) } } } public func deleteLog(_ indexSet: IndexSet) { for index in indexSet { let chat = chatLog[index] modelContext.delete(chat) // do { // try modelContext.save() // // } catch { // // print("Error saving: \(error)") // // } } } }
Replies
Boosts
Views
Activity
Jun ’24
Reply to SwiftUI: Extra line in NavigationStack
The 2 NavigationTitles are for the listView and then the DetaiView. The data.name is coming from an array thats in another Swift file. Its where the information is coming from. I did not know about pasting code with the Paste and Match style. I'll remember that for the next time. Here's a screen shot of the previous screen before the original one. Thanks.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to Xcodes files gone missing
Try this: Close Xcode. Reboot the Mac. Reload Xcode. Reload project. BUT before trying to run it, clear project files. If it still shows red files, look for those files manually in the Finder or recreate them. Dan Uff
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’22