Skip to content

Commit ecac294

Browse files
authored
fix(objc): Workaround for Swift/ObjC template issues (#1494)
This uses "non-standard" Swift annotations, but they've been supported by the past few versions of Xcode and are in the process of being standardized. Most importantly, they work for what we need. Closes GH-1487.
1 parent 92df3b7 commit ecac294

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

templates/project/App/AppDelegate.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919

2020
#import <Cordova/CDVAppDelegate.h>
2121

22-
#warning It is unsafe to rely on the AppDelegate class as an extension point. \
23-
Update your code to extend CDVAppDelegate instead -- \
24-
This code will stop working in Cordova iOS 9!
22+
#ifndef __CORDOVA_SILENCE_HEADER_DEPRECATIONS
23+
#warning It is unsafe to rely on the AppDelegate class as an extension point. \
24+
Update your code to extend CDVAppDelegate instead -- \
25+
This code will stop working in Cordova iOS 9!
26+
#endif
2527

26-
@class AppDelegate;
27-
28-
#import "App-Swift.h"
28+
@interface AppDelegate : CDVAppDelegate
29+
@end

templates/project/App/AppDelegate.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
*/
1919

2020
import UIKit
21-
import Cordova
2221

2322
@main
24-
@objc // Remove compat hack in Cordova iOS 9
25-
class AppDelegate: CDVAppDelegate {
26-
override func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
23+
@_objcImplementation
24+
extension AppDelegate {
25+
open override func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
2726
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
2827
}
2928
}

templates/project/App/Bridging-Header.h

+5
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@
1818
*/
1919

2020
#import <Cordova/Cordova.h>
21+
22+
#define __CORDOVA_SILENCE_HEADER_DEPRECATIONS
23+
#import "AppDelegate.h"
24+
#import "MainViewController.h"
25+
#undef __CORDOVA_SILENCE_HEADER_DEPRECATIONS

templates/project/App/MainViewController.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919

2020
#import <Cordova/CDVViewController.h>
2121

22-
#warning It is unsafe to rely on the MainViewController class as an extension point. \
23-
Update your code to extend CDVViewController instead -- \
24-
This code will stop working in Cordova iOS 9!
22+
#ifndef __CORDOVA_SILENCE_HEADER_DEPRECATIONS
23+
#warning It is unsafe to rely on the MainViewController class as an extension point. \
24+
Update your code to extend CDVViewController instead -- \
25+
This code will stop working in Cordova iOS 9!
26+
#endif
2527

26-
@class MainViewController;
27-
28-
#import "App-Swift.h"
28+
@interface MainViewController : CDVViewController
29+
@end

templates/project/App/ViewController.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
import Cordova
2121

22-
@objc(MainViewController) // Remove compat hack in Cordova iOS 9
23-
class ViewController: CDVViewController {
22+
@_objcImplementation
23+
extension MainViewController {
2424
}
2525

26+
class ViewController: MainViewController {
27+
}

0 commit comments

Comments
 (0)