smallscript opened a new issue, #1288:
URL: https://github.com/apache/cordova-ios/issues/1288
# Bug Report
Currently CDVPlugin.m uses a `self = [super init]` pattern within the
`initWithWebViewEngine:` convenience initializer.
## Problem
The designated initializer pattern is used in place of a convenience
initializer pattern.
🧶👷 `convenience` initializers should invoke required `designated
initializers`
using `self`, as in `self = [self init]` 「not `self = [super
init]`」.
Specifically, when building a Swift based CDVPlugin subclass its `init`
never gets invoked.
Additionally, on iOS, this has a negative impact on plugin design because
`pluginInitialize` is
NOT an `init` method and it is only invoked (later) once the plugin has been
initialized and registered.
Which leads to ⟨confusion in design patterns⟩ many temporal configuration
times within the plugin architecture.
1) CDVPlugin subtype inst `self` being constructed and initialized.
「designated init」
2) `pluginInitialize` when plugin is registered-as-ready
3) JavaScript module/source has been loaded and configured the JS wrapper
4) `deviceReady` when JavaScript layer has been notified that Cordova itself
is all configured.
### What is expected to happen?
The Objective-C/Swift `convenience` initializer pattern for
`initWithWebViewEngine` invoking
`self = [self init]` 「not `self = [super init]`」.
### What does actually happen?
Currently the convenience-init `initWithWebViewEngine` is written as if it
were a designated-init calling a convenience-init.
It is using `self = [super init]`, which results in a Swift subclass never
having its `init` member
called and thus it never gets properly initialized if it has an `override
init` or any memberwise initializers.
Which, in turn, means it may not compile if it used `let` consts members or
it may simply crash due
to being uninitialized.
## Information
explained in other parts of this submission...
### Command or Code
Try the following changes with the swift plugin example below.
`self = [super init]` vs `self = [self init]` within `CDVPlugin.m` method
`initWithWebViewEngine:`.
```swift
class example : CDVPlugin {
let a: String = "never actually set";
let b: String;
override init() {b = "never actually set either";}
}
```
### Environment, Platform, Device
### Version information
- cordova platform version "ios 6.2.0"
- OSX version "Ventura 13.2.1"
## Checklist
- [ x] I searched for existing GitHub issues
- [ x] I updated all Cordova tooling to most recent version
- [ x] I included all the necessary information above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]