-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLLocationManager warnings fix #414
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🙌
return await withCheckedContinuation { continuation in | ||
authorizationContinuations.append(continuation) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we weakify self
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently it's not needed. Here's what ChatGPT says:
In this particular case, you do not need to weakly capture self inside the withCheckedContinuation block. Here’s why:
1. Continuation Blocks and Memory Management:
- The withCheckedContinuation block will be executed immediately and is not stored or retained beyond the duration of the call itself.
- Since the continuation is handled immediately and there’s no possibility of a strong reference cycle being created (where self would keep the block alive and the block would keep self alive), there's no need to weakly capture self in this context.
2. Scope and Lifetime:
- The self reference in the block is used to append the continuation to the authorizationContinuations array. Since the block is not stored and is only used in the context of this method, it won’t outlive the scope of the authorizationStatus method call.
3. Best Practices:
- Weakly capturing self is necessary when the block is retained by self or by an object that could cause a retain cycle, but that’s not the case here. The continuation is a temporary construct used to manage the async/await behavior and doesn’t introduce a strong reference cycle.
Conclusion:
In this scenario, you can safely capture self strongly within the withCheckedContinuation block. There’s no risk of a retain cycle, and the continuation is not retained beyond the method scope.
If the withCheckedContinuation were capturing self for an asynchronous operation that might last longer than the method scope (for example, if you were passing a closure to another long-lived object that could retain it), then you would need to consider capturing self weakly. But in this specific case, it’s not necessary.
Handle future cases to enum Co-authored-by: Benjamin Tegelaár-Breiby <Breiby@users.noreply.github.com>
Why?
We have a runtime warning when using CLLocationManager's
locationServicesEnabled()
What?
According to Apple's documentation, we should use a delegate function locationManagerDidChangeAuthorization(_:) to check the app's initial authorization state. The system guarantees to call it after init of
CLLocationManager
.Added a new
LocationService
to share logic between polygon and radius filter. The users of it can now get the authorization status, but the difference from before is that it's now async, since we have to wait for the delegate function to be called first.Show me
No UI change.