From 35cb9ac3668838b235c05b7e1dac13f57fd1133e Mon Sep 17 00:00:00 2001 From: Haritha Mohan <110641567+haritha-mohan@users.noreply.github.com> Date: Wed, 7 Sep 2022 14:58:41 -0700 Subject: [PATCH] [UIKit] Add nullability to file (#15857) File did not have nullability enabled. Add nullability and made some changes to code as safeguards. --- src/UIKit/UIGestureRecognizer.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/UIKit/UIGestureRecognizer.cs b/src/UIKit/UIGestureRecognizer.cs index efa52b18d3..8d6d674c7e 100644 --- a/src/UIKit/UIGestureRecognizer.cs +++ b/src/UIKit/UIGestureRecognizer.cs @@ -11,11 +11,10 @@ #if !WATCH using System; -using System.Collections; using System.Collections.Generic; using Foundation; using ObjCRuntime; -using CoreGraphics; +#nullable enable namespace UIKit { @@ -41,9 +40,9 @@ namespace UIKit { { var copyOfRecognizers = recognizers; var savedHandle = Handle; - recognizers = null; + recognizers = new Dictionary (); - if (copyOfRecognizers == null) + if (copyOfRecognizers.Count == 0) return; DangerousRetain (savedHandle); @@ -80,12 +79,12 @@ namespace UIKit { [Register ("__UIGestureRecognizerGenericCB")] internal class Callback : Token where T: UIGestureRecognizer { Action action; - + internal Callback (Action action) { this.action = action; } - + [Export ("target:")] [Preserve (Conditional = true)] public void Activated (T sender) => action (sender); @@ -168,7 +167,10 @@ namespace UIKit { // public IEnumerable GetTargets () { - return (IEnumerable) recognizers?.Keys ?? Array.Empty (); + var keys = recognizers?.Keys; + if (keys is null) + return Array.Empty (); + return (IEnumerable) keys; } }