When my Swift program stops at a breakpoint values for some of the variables that appear to be available for inspection are shown, but most are not. The variables themselves are listed, but no values are shown when I look at them. The code snippet is the addItem function in the default ContentView for a Swift project, somewhat modified for my particular purpose.
Stopping at a breakpoint in this function I am able to see the value for the variable zz, but properties of the Ledger and LedgerEntry structures seem to have no values. I can inspect them, but they all show 'Value: None'. Even those values that have been explicitly defined are not displayed.
Here's what I see when I print the debugger's description of these couple of properties:
Printing description of newEntry._ix:
(PennyJar.LedgerEntry._SwiftDataNoType) _ix = {}
Printing description of newLedger._type:
(PennyJar.Ledger._SwiftDataNoType) _type = {}
I have read what I can find on the forums, and I've checked all the suggested build parameters, which all seem to be correctly indicating a Debug build with no Optimization.
I would really appreciate any guidance from someone who knows these tools... Thanks in advance!
@Model
final class Ledger {
var id = UUID()
var name: String
var type: String
var entries: [LedgerEntry]
init(name: String) {
self.name = name
self.type = ""
self.entries = []
}
}
@Model
final class LedgerEntry {
let id = UUID()
var ix: Int = 0
var date: String
var chkno: String
var payee: String
var category: String
var debit: Float
var credit: Float
init(ledger: Ledger) {
self.ix = 0
self.date = "1/21/24"
self.chkno = ""
self.payee = ""
self.category = ""
self.debit = 0
self.credit = 0
}
}
private func addItem() {
withAnimation {
let zz = 27
let newLedger = Ledger(name: "New Ledger")
let newEntry = LedgerEntry(ledger: newLedger)
newEntry.payee = "Initial Balance"
newEntry.ix = 1
newLedger.entries.append(newEntry)
modelContext.insert(newLedger)
}
}