Closed jaysonng closed 1 year ago
Call some query on the same view where you run ParseSwift.initialize()
You are calling your initializer way too late if you are calling it in a view. In addition, placing the Swift SDK init in a view may cause it to be called multiple times, which can lead to a ton of other issues.
The Swift SDK should be called once, and it should be called early when the app opens, which is why it has historically been in the AppDelegate
.
I can try to submit a partial fix, but your current design will continue to lead to issues as views can be regenerated, causing the SDK to be reinitialized.
I see. I just moved it to the @main view.
I guess ill copy how you have it setup on carekit with the appdelegate. :) thanks again
The linked PR and version should fix the direct issue you are facing.
I guess ill copy how you have it setup on carekit with the appdelegate.
If you are looking through the CareKit example, this branch is cleaner and will be merged in the near future: https://github.com/netreconlab/CareKitSample-ParseCareKit/tree/newCareKit
You will want to setup your AppDelegate
in a similar way:
@UIApplicationDelegateAdaptor(AppDelegate.self)
. You can pass it through the environment if you intend to use AppDelegate
in other places of your app: https://github.com/netreconlab/CareKitSample-ParseCareKit/blob/f5965788f28eee84a4eab382ab785e3badd6a1c6/OCKSample/OCKSampleApp.swift#L15-L22AppDelegate
class conform to ObservableObject
and use @Published
for any properties you want to update your views https://github.com/netreconlab/CareKitSample-ParseCareKit/blob/f5965788f28eee84a4eab382ab785e3badd6a1c6/OCKSample/AppDelegate.swift#L39-L42PCKUtility.configureParse()
calls ParseSwift init, so if you are interested in using a .plist
file to configure ParseSwift, see: https://github.com/netreconlab/ParseCareKit/blob/566f68ef230e4285eb9e19a3d1045947d5a74eef/Sources/ParseCareKit/PCKUtility.swift#L18-L94
New Issue Checklist
Issue Description
"Thread 4: Swift runtime failure: Unexpectedly found nil while implicitly unwrapping an Optional value"
when running query with .includeAll() on my @main app file.
The error specifically comes from the firstCommand() function in Query.swift
Steps to reproduce
Call some query on the same view where you run ParseSwift.initialize()
In my case, ParseSwift.initilize is called within init() in a Task { }
I receive this warning in the console for the few times that it does not crash
nw_resolver_start_query_timer_block_invoke [C1.1.1] Query fired: did not receive all answers in time for xxxxxxxxx:443
Actual Outcome
A lot of the times it crashes with the said error. only some of the time does it work as expected.
Expected Outcome
There should be no crash and the query should be called after initialization of Parse.
Environment
Client
5.4.1
14.3
iPad OS, iOS, MacOS simulator
16.4.1
Server
5.2.4
Heroku
Database
MongoDB
Local Heroku
Logs