-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat(ios): CAPPluginMethod selector-based initializer #7412
Conversation
selector. Creates a convenience initializer as well with a Swift enum.
|
||
extension CAPPluginMethod { | ||
public enum ReturnType: String { | ||
case promise, callback |
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 add the none
return type?
it's not used by any plugin other than console (as far as I know)
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.
We definitely could. none
is weird in that the web code treats anything that is not a promise as a callback https://github.com/ionic-team/capacitor/blob/main/core/src/runtime.ts#L123-L133. The docs are actually misleading https://capacitorjs.com/docs/plugins/method-types#void-return in that it says "You can check the promise for an error but when it resolves the result is ignored" because you can't actually check for an error.
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.
let's add it, so if we want to do a refactor in the future for the core plugins, we can use this new initializer in all of them instead of having to use a different one for Console plugin
Add secondary initializer for CAPPluginMethod that takes a selector. Creates a convenience initializer as well with a Swift enum to avoid having to rely on global string values in the style of CAPPluginReturnPromise. For a pure Swift plugin implementation, it makes the definition potentially go from:
to this:
A benefit of this approach include removing the need to stringify the name of the function. This will also validate the selector at compile time, so if it has not been annotated with
@objc
it will be a compiler error.