[PLAT-7417] Add new APIs for removing Swift callbacks #1240
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.
Goal
Make it possible to remove Swift
OnBreadcrumb
,OnSendError
andOnSession
closures.removeOnBreadcrumbBlock
not working from swift #1203Design
When a Swift closure is passed to
addOnBreadcrumb(block:)
orremoveOnBreadcrumb(block:)
the compiler creates anNSBlock
which "wraps" the closure and makes it callable from Objective-C. When Bugsnag is asked to remove a previously added callback, testing the objects for equality always fails and the original block cannot be identified in the array.This PR makes it possible to remove closures by passing the object from
addOnBreadcrumb(block:)
to a newremoveOnBreadcrumb(_:)
function. For simplicity of implementation,addOnBreadcrumb(block:)
returns the (copy of the) block that was added to the array.The old
removeOnBreadcrumb(block:)
function has been marked as deprecated.The new
removeOnBreadcrumb(_:)
function method accepts anAnyObject
to cause a compile error if misused by passing it a closure.Note: all this also applies to
OnSendError
andOnSession
.Testing
Existing unit tests amended to verify new APIs, new test cases added to verify passing invalid values to the remove: APIs.