Post

Replies

Boosts

Views

Activity

SwiftData nested custom model CRASH
@Model class AModel { @Attribute(.unique) var id:String var date:Date var b:[BModel] init() { self.id = UUID().uuidString self.date = Date() self.b = [] } } @Model class BModel { @Attribute(.unique) var id:String var date:Date init() { self.id = UUID().uuidString self.date = Date() } } struct MainView: View { @Environment(\.modelContext) private var db @State private var a:AModel = AModel() var body: some View { VStack { } .onAppear { a.b.append(BModel()) print(a.b) } } } // CRASH : @Model class AModel { @Attribute(.unique) var id:String var date:Date var b:[BModel] /** Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) { get { _$observationRegistrar.access(self, keyPath: \.b) return self.getValue(for: \.b) } set { _$observationRegistrar.withMutation(of: self, keyPath: \.b) { self.setValue(for: \.b, to: newValue) } } } */ init() { self.id = UUID().uuidString self.date = Date() self.b = [] } } @Model class BModel { @Attribute(.unique) var id:String var date:Date init() { self.id = UUID().uuidString self.date = Date() } }
3
4
1.7k
Jun ’23
swiftdata : isAutosaveEnabled, isUndoEnabled - xcode15b4 - ios17
When you set your container "manually", how can we interact with the isAutosaveEnabled and isUndoEnabled parameters from the modelContainer ? let schema:Schema = Schema([ Model.self ]) let configuration:ModelConfiguration = ModelConfiguration() let container:ModelContainer = try ModelContainer(for:schema, configuration) let context:ModelContext = ModelContext(container)
2
2
700
Jul ’23
Tabview dont update the tab selection anymore xcode15b3 ios17
When navigating with the screen, the tab selection should be updated accordingly but it does not. I try with the observable protocol or with the state property wrapper, same results... import SwiftUI import SwiftData struct MainView: View { @Environment(\.modelContext) private var db @Environment(NavigationObservable.self) private var navigationObservable // @State private var tab:String = "tab1" var body: some View { TabView( selection:Binding( get: { navigationObservable.tab }, set: { newValue in navigationObservable.tab = newValue } ) ) { // TabView( // selection:$tab // ) { Text("tab1") .tag("tab1") Text("tab2") .tag("tab2") } .tabViewStyle(.page(indexDisplayMode:.never)) .onChange(of: navigationObservable.tab) { print(navigationObservable.tab) } // .onChange(of: tab) { // print(tab) // } } }
0
0
705
Jul ’23
swiftdata relationship xcode15b3 ios17
I can't find a way to make this relationship, Anyone to tell me what am i doing wrong please ? import SwiftUI import SwiftData @Model class Model1 { @Attribute(.unique) var id:String var date:Date @Relationship(.cascade) var model2:[Model2] init() { self.id = UUID().uuidString self.date = Date() self.model2 = [] } } @Model class Model2 { @Attribute(.unique) var id:String var date:Date @Relationship(inverse: \Model1.model2) var model1:Model1 init( model1:Model1 ) { self.id = UUID().uuidString self.date = Date() self.model1 = model1 } } struct view1:View { @Environment(\.modelContext) private var db var body: some View { Text("TapMe") .onTapGesture { let m1 = Model1() db.insert(m1) let m2 = Model2(model1: m1) db.insert(m2) } } } Error : Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Illegal attempt to establish a relationship 'm1' between objects in different contexts (source = <NSManagedObject: 0x280b253b0> (entity: Model2; id: 0x282896ca0 <x-coredata:///Model2/tCB971C15-AFE3-46A2-A1FB-E688E0EF2ABF207>; data: { date = "2023-07-10 20:22:56 +0000"; id = "625B994D-24BB-4935-A438-8AA6522C0FE1"; m1 = nil; }) , destination = <NSManagedObject: 0x280b250e0> (entity: Model1; id: 0x2828eaa40 <x-coredata:///Model1/tCB971C15-AFE3-46A2-A1FB-E688E0EF2ABF206>; data: { date = "2023-07-10 20:22:56 +0000"; id = "BA3E6CF3-67EC-41CA-A150-E66E0D7226B2"; m2 = ( ); }))'
1
1
1.1k
Jul ’23
swiftui : tabview ios16 vs ios15** : glitchy and no animation
Hello, Since iOS16, I noticed a glitch when switching from tabN to tabN+1 or tabN-1 and reverse with complex embedded view. Also the animation to switch tab programmatically are no longer working when I use an observableObject as a selection : @EnvironmentObject var ViewModel: VM TabView(selection: $ViewModel.tabRouter) { View1() .tag("first") View2() .tag("second") View3() .tag("third") } .animation(.default, value: ViewModel.tabRouter) .tabViewStyle(.page(indexDisplayMode: .never)) .ignoresSafeArea(edges: .bottom) On iOS15 everything works smoothly. Best
0
0
1.1k
Oct ’22