Ensuring initialize
has returned before attempting queries.
#167
-
Very infrequently, I run in to a crash along the lines of: ParseSwift/Parse.swift:106: Fatal error: Unexpectedly found nil while unwrapping an Optional value Here is my AppDelegate: @main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Task {
guard let AppID = Secrets.App_ID,
let ClientKey = Secrets.Cli_ID,
let AppURL, let LiveURL
else { fatalError("Incorrect implementation of Secrets") }
let config = ParseConfiguration(AppID, ClientKey, AppURL, LiveURL)
try await initialize(configuration: config)
}
return true
}
} I was hesitant to report it since I can't reproduce it consistently, but I thought I'd flag it anyway just in case you: Line 106 is the following: l104 /// The current `ParseConfiguration` for the ParseSwift client.
l105 public var configuration: ParseConfiguration {
l106 Parse.configuration
l107 } Questions
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Can you post the code for how your app attempts to make its first Swift call (this can be a login, query, or parse installation call)? If you climb up the debug stack when the error occurs, you should be able to find the exact line causing the problem. To reproduce the error consistently, add a delay of ~5 seconds right before
See thread #37 (reply in thread) |
Beta Was this translation helpful? Give feedback.
-
I can confirm that adding in the delay consistently reproduces the error.
So once didFinishLaunching runs, it launches my (simplified) class HomeVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Task {
do { try await fetch() }
catch { print(error) }
}
}
func fetch() async throws {
let staff = Staff(objectId: "someObjectID")
let slip = try await Payslip.query("staff_" == staff).first()
}
}
The thread seems to suggest that this issue doesn't exist after v5.0.1 but I'm running v5.9.2 |
Beta Was this translation helpful? Give feedback.
PR 168 won't fix your crash. To address your issue, you will have to make a change to your code to prevent the crash as the fix that needs to be made is a breaking change to the SDK. You need to do the following:
The problem is you are using the old appDelegate lifecycle and your viewDidLoad is being called before the Swift SDK finishes…