Skip to content

Commit 5cf4d94

Browse files
authored
fix(Swift): Nullability stuff broke Swift compatibility (#1521)
CDVPlugin's commandDelegate is a weak pointer, which means technically in Swift it should be an optional type that requires unwrapping. For some reason, it is not. If the wrap the CDVPlugin class in the ASSUME_NONNULL macro, Swift suddenly starts enforcing that it's an optional, and this breaks all existing Swift plugins. You aren't allowed to combine `weak` and `nonnull`, and all the properties in CDVPlugin are weak, so just... don't wrap it in ASSUME_NONNULL to make life easier for everyone 🙃
1 parent 12aeeb4 commit 5cf4d94

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

CordovaLib/include/Cordova/CDVPlugin.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
typedef int CDVWebViewNavigationType;
3434

35+
NS_ASSUME_NONNULL_BEGIN
36+
3537
#ifndef __swift__
3638
// This global extension to the UIView class causes issues for Swift subclasses
3739
// of UIView with their own scrollView properties, so we're removing it from
@@ -42,8 +44,6 @@ typedef int CDVWebViewNavigationType;
4244
@end
4345
#endif
4446

45-
NS_ASSUME_NONNULL_BEGIN
46-
4747
extern const NSNotificationName CDVPageDidLoadNotification;
4848
extern const NSNotificationName CDVPluginHandleOpenURLNotification;
4949
extern const NSNotificationName CDVPluginHandleOpenURLWithAppSourceAndAnnotationNotification CDV_DEPRECATED(8, "Find sourceApplication and annotations in the userInfo of the CDVPluginHandleOpenURLNotification notification.");
@@ -56,6 +56,8 @@ extern const NSNotificationName CDVViewWillLayoutSubviewsNotification;
5656
extern const NSNotificationName CDVViewDidLayoutSubviewsNotification;
5757
extern const NSNotificationName CDVViewWillTransitionToSizeNotification;
5858

59+
NS_ASSUME_NONNULL_END
60+
5961
@interface CDVPlugin : NSObject {}
6062

6163
@property (nonatomic, readonly, weak) UIView* webView;
@@ -68,8 +70,8 @@ extern const NSNotificationName CDVViewWillTransitionToSizeNotification;
6870

6971
- (void)pluginInitialize;
7072

71-
- (void)handleOpenURL:(NSNotification*)notification;
72-
- (void)handleOpenURLWithApplicationSourceAndAnnotation:(NSNotification*)notification CDV_DEPRECATED(8, "Use the handleOpenUrl method and the notification userInfo data.");
73+
- (void)handleOpenURL:(nonnull NSNotification*)notification;
74+
- (void)handleOpenURLWithApplicationSourceAndAnnotation:(nonnull NSNotification*)notification CDV_DEPRECATED(8, "Use the handleOpenUrl method and the notification userInfo data.");
7375
- (void)onAppTerminate;
7476
- (void)onMemoryWarning;
7577
- (void)onReset;
@@ -83,12 +85,14 @@ extern const NSNotificationName CDVViewWillTransitionToSizeNotification;
8385
- (void) onOrientationDidChange {}
8486
*/
8587

86-
- (id)appDelegate;
88+
- (nonnull id)appDelegate;
8789

8890
@end
8991

9092
#pragma mark - Plugin protocols
9193

94+
NS_ASSUME_NONNULL_BEGIN
95+
9296
/**
9397
A protocol for Cordova plugins to intercept and respond to server
9498
authentication challenges through WebKit.

0 commit comments

Comments
 (0)