Fix bug where HTTP requests were incorrectly cancelled #168
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
hopefully fixes #167
First, I changed the HTTP call from
.data()
to.dataTask()
with a completion handler. I did this, because I couldn't find out, which exact line was throwing the exception, when the request was cancelled.Because I didn't want to change the rest of the class, I wrapped this new call inside
withCheckedThrowingContinuation()
to turn this into an async call.This didn't fix the issue completely, because there was a new warning in the log:
This error told me, what happened to the running tasks when navigating quickly: Something is wrong with the memory management of this class.
So I switched the property
grocyVM
in the views from@SteteObject
to@ObservedObject
, which is recommended for properties that are not created inside the view, but injected instead: https://www.avanderlee.com/swiftui/stateobject-observedobject-differences/#should-i-use-stateobject-for-all-views-using-the-same-instance