Issue with SwiftData: “no such table: ZAPPSETTINGS” and SQLite I/O error on app launch
Hello,
I’m encountering persistent errors with SwiftData in my SwiftUI app related to Core Data’s underlying SQLite database. Despite defining my models correctly, the app fails to initialize the persistent store, throwing the following error on startup:
CoreData error: SQLCore dispatchRequest: no such table: ZAPPSETTINGS. I/O error opening database at /.../default.store. SQLite error code:1, NSSQLiteErrorDomain=1.
File “default.store” couldn’t be opened.
Context
The error only appears concerning my AppSettings model.
I have another model, LocationPoint, which appears correctly defined and used.
I have tried deleting the app, resetting the device, and cleaning builds but the error persists.
The error message suggests the database file is present but the table for ZAPPSETTINGS (the Core Data table for AppSettings) does not exist.
Code Samples
Main App Entry
import SwiftData
import SwiftUI
@main
struct Krow3_0App: App {
@State private var userLocationManager = UserLocationManager()
@State private var geocodingViewModel = GeocodingViewModel()
@State private var locationSearchViewModel = LocationSearchViewModel()
@State private var router = Router()
var body: some Scene {
WindowGroup {
LaunchView()
.environment(userLocationManager)
.environment(geocodingViewModel)
.environment(locationSearchViewModel)
.environment(router)
.modelContainer(for: [LocationPoint.self, AppSettings.self])
}
}
}
AppSettings Model
import Foundation
import SwiftData
@Model
class AppSettings {
var isMetric: Bool
init(isMetric: Bool = false) {
self.isMetric = isMetric
}
}
What I’ve Tried
Fully uninstalling and reinstalling the app on device and simulator.
Resetting the simulator/device.
Cleaning the Xcode build folder.
Verifying the schema logs which correctly list both LocationPoint and AppSettings.
Changing model names to avoid potential conflicts.
Adding .modelContainer configuration with autosave enabled.
Questions
Is there a known bug or limitation with SwiftData concerning certain model setups or naming?
Could this be related to how the data container initializes or migrates schemas?
Are there recommended debugging or migration steps to resolve “no such table” SQLite errors with SwiftData?
How can I safely reset or migrate the persistent store without corrupting the database?
Any insights or suggestions would be greatly appreciated!
Thank you!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
How do I get data like move and exercise time from HealthKit
import SwiftUI
import HealthKit
struct Health: View {
var body: some View {
let healthStore = HKHealthStore()
let objectTypes: SetHKObjectType = [
HKObjectType.activitySummaryType()
]
healthStore.requestAuthorization(toShare: nil, read: objectTypes) { (success, error) in
// Authorization request finished, hopefully the user allowed access!
let calendar = Calendar.autoupdatingCurrent
var dateComponents = calendar.dateComponents(
[ .year, .month, .day ],
from: Date()
)
// This line is required to make the whole thing work
dateComponents.calendar = calendar
let predicate = HKQuery.predicateForActivitySummary(with: dateComponents)
et; query = HKActivitySummaryQuery(predicate: predicate) { (query, summaries, error) in
guard let summaries = summaries, summaries.count 0
else {
return
}
let sandUnit = HKUnit.count()
let standHours = summary.appleStandHours.doubleValue(for: standUnit)
}
}
}
}
struct Health_Previews: PreviewProvider {
static var previews: some View {
Health()
}
}
This is my current code -
It does not work
How can I improve this to get the values out of the HealthKit object