Posts

Post not yet marked as solved
1 Replies
850 Views
I'm a newbie in working with SwiftData and I hope for your help in solving the below issue :") It's about deleting the objects into a Model by ModelContext.delete(). It's only possible to delete the data after it has been inserted for about 30 seconds. Just run the source code below, tap on "Add" button to add some samples, and then tap on "Delete" button right away. At this time, Delete action doesn't work. You have to wait about 30 seconds, then tap on "Delete" button, it will work - the sample data are deleted properly. I tested this issue on Xcode 15.1 beta (15C5042i) and found that: This issue always happens on Preview w/ iOS 17 or iOS 17.2. This issue doesn't happen on Simulator w/ iOS 17 BUT it happens on Simulator w/ iOS 17.2 Is this an issue of iOS 17.2 ? Full source code on GitHub Bike.swift import Foundation import SwiftData @Model class Bike { var name: String init(name: String) { self.name = name } } TestApp.swift import SwiftUI import SwiftData @main struct TestApp: App { var body: some Scene { WindowGroup { BikeListView() } .modelContainer(for: Bike.self) } } BikeListView.swift import SwiftUI import SwiftData struct BikeListView: View { @Environment(\.modelContext) var modelContext @Query var bikes: [Bike] var body: some View { VStack { HStack(spacing: 30) { Button { addSamples() } label: { Text("Add") } Button { deleteSamples() } label: { Text("Delete") } } List { ForEach(bikes) { eachBike in Text(eachBike.name) } } } } func addSamples() { let bikeOne = Bike(name: "One") let bikeTwo = Bike(name: "Two") modelContext.insert(bikeOne) modelContext.insert(bikeTwo) } func deleteSamples() { try? modelContext.delete(model: Bike.self) } } #Preview { do { let modelConfig = ModelConfiguration(isStoredInMemoryOnly: false) let modelContainer = try ModelContainer(for: Bike.self, configurations: modelConfig) return BikeListView() .modelContainer(modelContainer) } catch { fatalError("Content View's Preview") } } Thanks for reading and I'm looking forward to your help.
Posted
by tuan-pham.
Last updated
.
Post not yet marked as solved
1 Replies
815 Views
I'm a newbie in working with SwiftData and I hope for your help in solving the below issue :") It's about adding new objects into a Model, it takes about 30 seconds to save the data after executing modelContext.insert(). Just run the source code below, tap on "Add" button to add some samples, and then tap on "Delete" button right away. Delete action doesn't work immediately, but it's about 30 seconds after tapping on the "Add" button, it will work - the sample data are deleted properly. I tested and found this issue happens on both Preview and Simulator of: Xcode 15.0 (15A240d) and iOS 17.0 Xcode 15.1 beta (15C5042i) with iOS 17.2 Full source code on GitHub Bike.swift import Foundation import SwiftData @Model class Bike { var name: String init(name: String) { self.name = name } } TestApp.swift import SwiftUI import SwiftData @main struct TestApp: App { var body: some Scene { WindowGroup { BikeListView() } .modelContainer(for: Bike.self) } } BikeListView.swift import SwiftUI import SwiftData struct BikeListView: View { @Environment(\.modelContext) var modelContext @Query var bikes: [Bike] var body: some View { VStack { HStack(spacing: 30) { Button { addSamples() } label: { Text("Add") } Button { deleteSamples() } label: { Text("Delete") } } List { ForEach(bikes) { eachBike in Text(eachBike.name) } } } } func addSamples() { let bikeOne = Bike(name: "One") let bikeTwo = Bike(name: "Two") modelContext.insert(bikeOne) modelContext.insert(bikeTwo) } func deleteSamples() { try? modelContext.delete(model: Bike.self) } } #Preview { do { let modelConfig = ModelConfiguration(isStoredInMemoryOnly: true) let modelContainer = try ModelContainer(for: Bike.self, configurations: modelConfig) return BikeListView() .modelContainer(modelContainer) } catch { fatalError("Content View's Preview") } } Thanks for reading and I'm looking forward to your help.
Posted
by tuan-pham.
Last updated
.
Post not yet marked as solved
0 Replies
570 Views
I'm an iOS beginner. I'm facing an issue with the trigger order of Tap Gesture which is applied to NavigationView and its subview - a Circle view. When I tap on the Circle view, I expect that the system always prioritizes the Tap Gesture action of the Circle view over the Tap Gesture action of the NavigationView, BUT the result is not always like that. Specifically, sometimes the system gives: Navigation tapped Circle tapped sometimes the system gives Circle tapped Navigation tapped The code is as below or on Gist: struct ContentView: View { var body: some View { NavigationStack { VStack { // Button { // print("Circle tapped") // } label: { // Circle() // .fill(.red) // .frame(width: 200, height: 200) // } Circle() .fill(.red) .frame(width: 200, height: 200) .onTapGesture { print("Circle tapped") } } } // .simultaneousGesture(TapGesture().onEnded({ _ in // print("Navigation tapped") // })) .onTapGesture { print("Navigation tapped") } } } What I tried (as commented code) but failed: use simulatneousGesture modifier. use Button w/ label as a Circle. Is there any way to make the system always prioritize the Tap Gesture of the Circle over the Tap Gesture of the Navigation View? Thanks for your reading and I appreciate your help.
Posted
by tuan-pham.
Last updated
.