Skip to content

Commit

Permalink
fix(Swift): Nullability stuff broke Swift compatibility (#1521)
Browse files Browse the repository at this point in the history
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 🙃
  • Loading branch information
dpogue authored Jan 17, 2025
1 parent 12aeeb4 commit 5cf4d94
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions CordovaLib/include/Cordova/CDVPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

typedef int CDVWebViewNavigationType;

NS_ASSUME_NONNULL_BEGIN

#ifndef __swift__
// This global extension to the UIView class causes issues for Swift subclasses
// of UIView with their own scrollView properties, so we're removing it from
Expand All @@ -42,8 +44,6 @@ typedef int CDVWebViewNavigationType;
@end
#endif

NS_ASSUME_NONNULL_BEGIN

extern const NSNotificationName CDVPageDidLoadNotification;
extern const NSNotificationName CDVPluginHandleOpenURLNotification;
extern const NSNotificationName CDVPluginHandleOpenURLWithAppSourceAndAnnotationNotification CDV_DEPRECATED(8, "Find sourceApplication and annotations in the userInfo of the CDVPluginHandleOpenURLNotification notification.");
Expand All @@ -56,6 +56,8 @@ extern const NSNotificationName CDVViewWillLayoutSubviewsNotification;
extern const NSNotificationName CDVViewDidLayoutSubviewsNotification;
extern const NSNotificationName CDVViewWillTransitionToSizeNotification;

NS_ASSUME_NONNULL_END

@interface CDVPlugin : NSObject {}

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

- (void)pluginInitialize;

- (void)handleOpenURL:(NSNotification*)notification;
- (void)handleOpenURLWithApplicationSourceAndAnnotation:(NSNotification*)notification CDV_DEPRECATED(8, "Use the handleOpenUrl method and the notification userInfo data.");
- (void)handleOpenURL:(nonnull NSNotification*)notification;
- (void)handleOpenURLWithApplicationSourceAndAnnotation:(nonnull NSNotification*)notification CDV_DEPRECATED(8, "Use the handleOpenUrl method and the notification userInfo data.");
- (void)onAppTerminate;
- (void)onMemoryWarning;
- (void)onReset;
Expand All @@ -83,12 +85,14 @@ extern const NSNotificationName CDVViewWillTransitionToSizeNotification;
- (void) onOrientationDidChange {}
*/

- (id)appDelegate;
- (nonnull id)appDelegate;

@end

#pragma mark - Plugin protocols

NS_ASSUME_NONNULL_BEGIN

/**
A protocol for Cordova plugins to intercept and respond to server
authentication challenges through WebKit.
Expand Down

0 comments on commit 5cf4d94

Please sign in to comment.