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.
Platforms affected
iOS
Motivation and Context
Fixes #1288
Description
This ensures that the default
init
method is called for CDVPlugin subclasses, to allow Swift initializers to run as expected.Aside: I still feel like
NS_DESIGNATED_INITIALIZER
would be the theoretically correct way to solve this, but that doesn't work when our designated initializer with the webview is part of private implementation details (your designated initializer must be part of your public API surface).The risk is that someone could (in their own code) do
[[MyCordovaPlugin alloc] init]
and try to construct a plugin instance without providing the webview engine, and lead to all sorts of weird issues.However, that problem already existed and people don't seem to be shooting themselves in the foot with it (or at least, not complaining here when they do), so it's probably better to fix the issue that is impacting people even if the solution isn't theoretically perfect.
Testing
Added a unit test which ensures that an init-time property in a Swift plugin is correctly set after the plugin has been initialized. This test case fails without the changes to CDVPlugin.m.
Checklist
(platform)
if this change only applies to one platform (e.g.(android)
)