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

CB-10071: (ios) Proposal swift support #107

Merged
merged 2 commits into from
Sep 12, 2018

Conversation

knight9999
Copy link
Contributor

The purpose of this proposal is to support iOS plugin written by Swift.
I propose introducing two functions.

  • The first function will edit the Bridging-Header.h according to the settings defined in plugin.xml.

  • The second is setting the application’s Swift version according to the settings defined in config.xml.

Note that we can specify the Swift version for the application. Plugins with different Swift version can not be imported simultaneously. This is contrary with CocoaPod libraries in which Swift version can be specified for each.

@dpogue
Copy link
Member

dpogue commented Aug 6, 2018

This seems good, and should remove the need for people to fiddle with hook scripts or extra plugins just to get Swift working.

Regarding plugins written in Swift, how do you envision they would specify the compatible Swift version? I guess they could inject it into the platform's config.xml and let the app's config.xml override it?

Plugin specifies Swift 4.0 in its plugin.xml:

<!-- plugin.xml -->
<plugin ...>
  <platform name="ios">
    <config-file parent="/*" target="config.xml">
      <preference name="SwiftVersion" value="4.0" />
    </config-file>
  </platform>
</plugin>

Application config.xml specifies Swift 4.1:

<!-- config.xml -->
<widget ...>
  <platform name="ios">
    <preference name="SwiftVersion" value="4.1." />
  </platform>
</widget>

Result: Swift 4.1

@knight9999
Copy link
Contributor Author

Thanks @dpogue

I did not assume that the plugin specifies its own swift version.
I thought that the developer should specify the swift version by his application config.xml,
like a NSCameraUsageDescription in cordova-camera-plugin where the developer
should specify the 'NSCameraUsageDescription' in his application config.xml.

However, as you said that, the application config.xml can override plugin's preferences.

It is a good rule that the plugin has its own default swift version and the developer
overrides it by using application config.xml if necessary.

Anyway choosing swift version is totally developer's responsibility.
There is no guarantee that will work for different swift version.

@shazron
Copy link
Member

shazron commented Aug 8, 2018

Sounds good. Are you planning to do this for cordova-ios@5, the next major version?

@dpogue
Copy link
Member

dpogue commented Aug 8, 2018

I think we should try to get this in for cordova-ios@5

@knight9999
Copy link
Contributor Author

Thanks @shazron @dpogue ..
I think so.

@knight9999
Copy link
Contributor Author

I have found one difficulty.

Assuming that there are two plugins, pluginA and pluginB.

  • pluginA is written in pure Obj-C plugin with the header file pluginA.h.

pluginB is written in pure Swift but depends on pluginA.

pluginB's methods need to call onto pluginA's methods.

In this use case, our specification is not enough.

To solve this issue, pluginB would be required to have an additional obj-c header file

pluginB.h

#import 'pluginA.h'

and in pluginB's plugin.xml file, specify this file as BridgingHeader.

<header-file src="src/ios/pluginB.h" type="BridgingHeader" />

@dpogue
Copy link
Member

dpogue commented Aug 16, 2018

That still seems acceptable. It makes sense that pluginB would be required to define its dependency on pluginA, even if the process for doing that involves an extra header file.

@knight9999
Copy link
Contributor Author

I have just sent two PRs.

PR for cordova-ios
apache/cordova-ios#395
This cordova-ios PR will require the following cordova-common PR to be merged first.

PR for cordova-common
apache/cordova-common#42

@knight9999
Copy link
Contributor Author

I have just sent a PR for cordova-doc.

apache/cordova-docs#880

Set status to completed
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.

5 participants