Wednesday, January 24, 2024
HomeiOS Developmentios - Swift UI Preview crashes when making calls to Swift Knowledge...

ios – Swift UI Preview crashes when making calls to Swift Knowledge associated strategies?


I’ve a Button in my View which calls an motion which both increments or deletes information from a Swift Knowledge mannequin.

On my cell system and the simulators, the app works completely. Nonetheless, within the SwiftUI preview that’s generated clicking on any button causes the preview to crash and dump logs.

That is all operating within the newest XCode construct 15.2

Button SwiftUI code:

Button("🍺", motion: { 
   self.recordDrink(drink:"beer")
}).buttonStyle(LiquorButtonStyle())

recordDrink()

personal func recordDrink(drink: String) {
    let dm = DrinkModel(drink: drink, date: Date())
    modelContext.insert(dm)
}

The crash generates the next logs:

Exception Kind:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000010663a938
Termination Cause: SIGNAL 5 Hint/BPT lure: 5
Terminating Course of: exc handler [8725]

Triggered by Thread:  0

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libswiftCore.dylib                     0x10663a938 _assertionFailure(_:_:file:line:flags:) + 248
1   SwiftData                              0x10533892c 0x105324000 + 84268
2   SwiftData                              0x1053a585c 0x105324000 + 530524
3   SwiftData                              0x1053a94dc 0x105324000 + 546012
4   SwiftData                              0x105368c30 0x105324000 + 281648
5   DrinkLess                              0x1043bfd68 DrinkModel.init(drink:date:) + 376 (@__swiftmacro_9DrinkLess0A5Model0C0fMm_.swift:2)
6   DrinkLess                              0x1043bfbe0 DrinkModel.__allocating_init(drink:date:) + 72
7   DrinkLess                              0x1043c5a6c CalculatorView.recordDrink(drink:) + 304 (CalculatorView.swift:74)
8   DrinkLess                              0x1043c5924 closure #1 in closure #1 in closure #1 in closure #1 in closure #1 in CalculatorView.physique.getter + 68 (CalculatorView.swift:44)

The logs dont comprise a lot data past line 8 speaking about closures.

My guess is both the SwiftUI preview cant appear to parse the Mannequin and the reads and writes to it, or one thing about placing the perform in a closure is inflicting issues, or a closure someplace down the road.

To reiterate, the app works wonderful on a bodily system. How do I repair the SwiftUI Preview setting?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments