Connection error when running on Mac in ‘Designed for iPad’ mode #65
-
I get a The same app works when run in the Simulator and on iPhones so I'm not sure what's going on here. Is there some additional debug output that I could enable to see why the connection isn't working? The database context setup would appear to work just fine, or at least I can dump the schema. The error only appears in the view where I have a import GRDB
import GRDBQuery
import SwiftUI
@main
struct RedactedApp: App {
var body: some Scene {
WindowGroup {
AppView()
}.databaseContext(.readOnly {
let dbURL = Bundle.main.path(forResource: "database", ofType: "sqlite3")!
var config = Configuration()
config.readonly = true
let dbQueue = try DatabaseQueue.inMemoryCopy(fromPath: dbURL, configuration: config)
try dbQueue.dumpSchema() // <-- Just for debugging. The schema dump is shown in
// the logs so the connection would appear to be working
return dbQueue
})
}
} Versions:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
hello @matiaskorhonen,
Thanks for checking that. You can dump the schema when you create the context, and this means that the connection is well established. Now, It looks like the database context present in the environment is not connected - it is likely the default database context, not the one you have configured. 🤔 I admit I lack experience about Mac apps in iPad compatibility mode. Could it be that the SwiftUI environment behaves differently? I would place this view somewhere in the app in order to test if the database context is connected: struct DatabaseConnectionTestView: View {
@Environment(\.databaseContext) var databaseContext
var body: some View {
Text(databaseValue())
}
private func databaseValue() -> String {
do {
return try databaseContext.reader.read { _ in "Success" }
} catch {
return String(describing: error)
}
}
} For example, I expect this app to display "Success". When I run it on my Mac (Sonoma 14.5, I'm late), in iPad compatibility mode, from with Xcode 16.2, it does: @main
struct RedactedApp: App {
var body: some Scene {
WindowGroup {
DatabaseConnectionTestView()
.databaseContext(.readOnly { try DatabaseQueue() })
}
}
} |
Beta Was this translation helpful? Give feedback.
This reminds me of early SwiftUI, where sheets would not inherit environment values.
Did you try to re-inject the environment in sheets?
If this works, it would be a good idea to submit a feedback to Apple.
This does not make sense, unless the queries fe…