Skip to content

Ensuring initialize has returned before attempting queries. #169

Closed
@cbaker6

Description

@cbaker6

Discussed in #167

Originally posted by project-saf March 28, 2024
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:
(a) wanted to know, and/or
(b) had any insight as to what might be causing the issue.
It definitely does crash with the same error if I comment out the Task in didFinishLaunching and then run a query.
My guess therefore is that it is some sort of issue with the login task being de-prioritised over some other Parse function like a query.

Line 106 is the following:

l104    /// The current `ParseConfiguration` for the ParseSwift client.
l105    public var configuration: ParseConfiguration {
l106        Parse.configuration
l107    }

Questions

  1. Is my AppDelegate code the intended way for Parse to be initialised?
  2. Is there a way to guarantee the login task completes either before returning from didFinishLaunching, or at least completes first before any other Tasks?
  3. Is it wise/possible to 'bake' into ParseSwift a means of ensuring that a query won't run until after the initialize function has completed? For example, a flag that makes those other tasks continue waiting until after initialize has returned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions