Skip to content

Commit e94fcc0

Browse files
committed
Handle legacy Swift versions
1 parent 9a433a6 commit e94fcc0

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@ This [Cordova plugin](https://www.npmjs.com/package/cordova-plugin-add-swift-sup
66

77
## Installation
88

9-
You can add this plugin directly to your project :
9+
You can add this plugin directly to your project:
1010

1111
`cordova plugin add cordova-plugin-add-swift-support --save`
1212

13-
Or add it as a dependency into your own plugin :
13+
Or add it as a dependency into your own plugin:
1414

1515
`<dependency id="cordova-plugin-add-swift-support" version="1.4.0"/>`
1616

17+
By default, the Swift 3 support is added but the legacy version (2.3) can still be configured as a preference:
18+
19+
`<preference name="UseLegacySwiftLanguageVersion" value="true" />`
20+
1721
If needed, add a prefixed Bridging-Header file in your plugin in order to import frameworks (MyPlugin-Bridging-Header.h for instance).
1822
As an example you can have a look at this [plugin](https://github.com/akofman/cordova-plugin-permissionScope).
1923

2024
If the `cordova-plugin-add-swift-support` plugin is already installed to your project, then you can add your own Swift plugin as usual, its prefixed Bridging-Header will be automatically found and merged.
2125

26+
2227
## License
2328

2429
Apache-2.0 © [Alexis Kofman](http://twitter.com/alexiskofman)

src/add-swift-support.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module.exports = function (context) {
3232
platformMetadata.getPlatformVersions(projectRoot).then(function (platformVersions) {
3333
var IOS_MIN_DEPLOYMENT_TARGET = '7.0';
3434
var platformPath = path.join(projectRoot, 'platforms', 'ios');
35+
var config = getConfigParser(context, path.join(projectRoot, 'config.xml'));
3536

3637
var bridgingHeaderPath;
3738
var bridgingHeaderContent;
@@ -57,7 +58,7 @@ module.exports = function (context) {
5758
return;
5859
}
5960

60-
projectName = getConfigParser(context, path.join(projectRoot, 'config.xml')).name();
61+
projectName = config.name();
6162
projectPath = path.join(platformPath, projectName);
6263
pbxprojPath = path.join(platformPath, projectName + '.xcodeproj', 'project.pbxproj');
6364
xcodeProject = xcode.project(pbxprojPath);
@@ -137,8 +138,13 @@ module.exports = function (context) {
137138
}
138139

139140
if (typeof xcodeProject.getBuildProperty('SWIFT_VERSION', buildConfig.name) === 'undefined') {
140-
xcodeProject.updateBuildProperty('SWIFT_VERSION', '3.0', buildConfig.name);
141-
console.log('Update SWIFT version to', 3.0, buildConfig.name);
141+
if (config.getPreference('UseLegacySwiftLanguageVersion', 'ios')) {
142+
xcodeProject.updateBuildProperty('SWIFT_VERSION', '2.3', buildConfig.name);
143+
console.log('Use legacy Swift language version', buildConfig.name);
144+
} else {
145+
xcodeProject.updateBuildProperty('SWIFT_VERSION', '3.0', buildConfig.name);
146+
console.log('Update SWIFT version to 3.0', buildConfig.name);
147+
}
142148
}
143149
}
144150
}
@@ -149,7 +155,7 @@ module.exports = function (context) {
149155
}
150156
};
151157

152-
function getConfigParser (context, config) {
158+
function getConfigParser (context, configPath) {
153159
var semver = context.requireCordovaModule('semver');
154160
var ConfigParser;
155161

@@ -159,7 +165,7 @@ function getConfigParser (context, config) {
159165
ConfigParser = context.requireCordovaModule('cordova-common/src/ConfigParser/ConfigParser');
160166
}
161167

162-
return new ConfigParser(config);
168+
return new ConfigParser(configPath);
163169
}
164170

165171
function getBridgingHeaderPath (context, projectPath, iosPlatformVersion) {

0 commit comments

Comments
 (0)