Skip to content
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

fix(CDVPlugin): Swift init #1295

Merged
merged 1 commit into from
Apr 14, 2023
Merged

fix(CDVPlugin): Swift init #1295

merged 1 commit into from
Apr 14, 2023

Conversation

dpogue
Copy link
Member

@dpogue dpogue commented Mar 3, 2023

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

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2023

Codecov Report

Merging #1295 (39b3fd4) into master (2c86d1a) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1295   +/-   ##
=======================================
  Coverage   78.45%   78.45%           
=======================================
  Files          15       15           
  Lines        1778     1778           
=======================================
  Hits         1395     1395           
  Misses        383      383           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@dpogue dpogue added this to the 7.0.0 milestone Apr 11, 2023
@erisu erisu changed the title Swift init fix: Swift init Apr 13, 2023
Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm if these two changes are expected?

The rest appears OK.

Will also need a rebase if possible.

Also add a test case to confirm that initializers work as expected with
Swift plugins.

Fixes apache#1288.
Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good to me. 👍 thanks!

@erisu erisu changed the title fix: Swift init fix(CDVPlugin): Swift init Apr 14, 2023
@erisu erisu merged commit bad7d87 into apache:master Apr 14, 2023
8 checks passed
@dpogue dpogue deleted the swift-init branch March 8, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

convenience init behavior within CDVPlugin.m for conformance to Swift init and let
4 participants