From 0cd7fcfee70ab4dd29fc1cd79a58c63d213f05c9 Mon Sep 17 00:00:00 2001 From: Copilot Date: Fri, 30 Jan 2026 16:57:53 +0100 Subject: [PATCH 1/2] [UIKit] Enable nullability and clean up UIAppearance. This is file 4 of 30 files with nullability disabled in UIKit. * Enable nullability (#nullable enable). * Remove unused System.Reflection using directive. * Use ArgumentNullException.ThrowIfNull() instead of manual null checks. * Add nullable annotations (UIAppearance?, object?). * Improve XML documentation comments: remove 'To be added.' placeholders, fix whitespace, add missing docs for operators and GetAppearance methods, add 'see cref' references. Contributes towards https://github.com/dotnet/macios/issues/17285. --- src/UIKit/UIAppearance.cs | 84 +++++++++---------- .../Documentation.KnownFailures.txt | 2 - .../expected/iOS-MonoVM-interpreter-size.txt | 10 +-- .../UnitTests/expected/iOS-MonoVM-size.txt | 6 +- .../UnitTests/expected/iOS-NativeAOT-size.txt | 6 +- 5 files changed, 53 insertions(+), 55 deletions(-) diff --git a/src/UIKit/UIAppearance.cs b/src/UIKit/UIAppearance.cs index ff65932d9651..84a341a8b70c 100644 --- a/src/UIKit/UIAppearance.cs +++ b/src/UIKit/UIAppearance.cs @@ -7,10 +7,7 @@ // Copyright 2011, 2015 Xamarin Inc // -using System.Reflection; - -// Disable until we get around to enable + fix any issues. -#nullable disable +#nullable enable namespace UIKit { #if __TVOS__ @@ -21,27 +18,29 @@ namespace UIKit { /// #endif public partial class UIAppearance { - /// To be added. - /// Whether this is equivalent to . - /// To be added. - /// To be added. - public override bool Equals (object other) + /// Determines whether the specified object is equal to the current . + /// The object to compare with the current instance. + /// if is a and has the same ; otherwise, . + public override bool Equals (object? other) { - UIAppearance ao = other as UIAppearance; + var ao = other as UIAppearance; if (ao is null) return false; return ao.Handle == Handle; } /// Generates a hash code for the current instance. - /// A int containing the hash code for this instance. - /// The algorithm used to generate the hash code is unspecified. + /// A hash code for the current instance. public override int GetHashCode () { return Handle.GetHashCode (); } - public static bool operator == (UIAppearance a, UIAppearance b) + /// Determines whether two instances have the same native handle. + /// The first instance to compare. + /// The second instance to compare. + /// if both instances are or have the same ; otherwise, . + public static bool operator == (UIAppearance? a, UIAppearance? b) { if (ReferenceEquals (a, null)) return ReferenceEquals (b, null); @@ -50,7 +49,11 @@ public override int GetHashCode () return a.Handle == b.Handle; } - public static bool operator != (UIAppearance a, UIAppearance b) + /// Determines whether two instances have different native handles. + /// The first instance to compare. + /// The second instance to compare. + /// if the instances have different native handles or exactly one is ; otherwise, . + public static bool operator != (UIAppearance? a, UIAppearance? b) { return !(a == b); } @@ -74,10 +77,12 @@ static IntPtr [] TypesToPointers (Type [] whenFoundIn) } #if TVOS - // new in iOS9 but the only option for tvOS const string selAppearanceWhenContainedInInstancesOfClasses = "appearanceWhenContainedInInstancesOfClasses:"; - // +(instancetype _Nonnull)appearanceWhenContainedInInstancesOfClasses:(NSArray> * _Nonnull)containerTypes + /// Gets the appearance proxy for a class in the specified containment hierarchy. + /// The Objective-C class pointer for the type to get the appearance proxy for. + /// The types representing the containment hierarchy in which the appearance should be applied. + /// The appearance proxy for the specified class when found in the specified containment hierarchy. public static IntPtr GetAppearance (IntPtr class_ptr, params Type [] whenFoundIn) { using (var array = NSArray.FromIntPtrs (TypesToPointers (whenFoundIn))) { @@ -88,11 +93,14 @@ public static IntPtr GetAppearance (IntPtr class_ptr, params Type [] whenFoundIn const string selAppearanceForTraitCollectionWhenContainedInInstancesOfClasses = "appearanceForTraitCollection:whenContainedInInstancesOfClasses:"; - // new in iOS9 but the only option for tvOS + /// Gets the appearance proxy for a class with the specified trait collection in the specified containment hierarchy. + /// The Objective-C class pointer for the type to get the appearance proxy for. + /// The for which to return the appearance proxy. + /// The types representing the containment hierarchy in which the appearance should be applied. + /// The appearance proxy for the specified class and traits when found in the specified containment hierarchy. public static IntPtr GetAppearance (IntPtr class_ptr, UITraitCollection traits, params Type [] whenFoundIn) { - if (traits is null) - throw new ArgumentNullException ("traits"); + ArgumentNullException.ThrowIfNull (traits); using (var array = NSArray.FromIntPtrs (TypesToPointers (whenFoundIn))) { IntPtr result = Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr (class_ptr, @@ -106,11 +114,10 @@ public static IntPtr GetAppearance (IntPtr class_ptr, UITraitCollection traits, const string selAppearanceWhenContainedIn = "appearanceWhenContainedIn:"; const string selAppearanceForTraitCollectionWhenContainedIn = "appearanceForTraitCollection:whenContainedIn:"; - /// To be added. - /// To be added. - /// This object's appearance proxy in the specified containment hierarchy. - /// To be added. - /// To be added. + /// Gets the appearance proxy for a class in the specified containment hierarchy. + /// The Objective-C class pointer for the type to get the appearance proxy for. + /// The types representing the containment hierarchy in which the appearance should be applied. + /// The appearance proxy for the specified class when found in the specified containment hierarchy. [BindingImpl (BindingImplOptions.Optimizable)] public static IntPtr GetAppearance (IntPtr class_ptr, params Type [] whenFoundIn) { @@ -127,17 +134,15 @@ public static IntPtr GetAppearance (IntPtr class_ptr, params Type [] whenFoundIn ptrs); } - /// To be added. - /// To be added. - /// To be added. - /// Returns an appearance proxy for the specified when found in the containment hierarchy. - /// To be added. - /// To be added. + /// Gets the appearance proxy for a class with the specified trait collection in the specified containment hierarchy. + /// The Objective-C class pointer for the type to get the appearance proxy for. + /// The for which to return the appearance proxy. + /// The types representing the containment hierarchy in which the appearance should be applied. + /// The appearance proxy for the specified class and traits when found in the specified containment hierarchy. [BindingImpl (BindingImplOptions.Optimizable)] public static IntPtr GetAppearance (IntPtr class_ptr, UITraitCollection traits, params Type [] whenFoundIn) { - if (traits is null) - throw new ArgumentNullException ("traits"); + ArgumentNullException.ThrowIfNull (traits); var ptrs = TypesToPointers (whenFoundIn); @@ -154,22 +159,17 @@ public static IntPtr GetAppearance (IntPtr class_ptr, UITraitCollection traits, GC.KeepAlive (traits); return result; } - - [DllImport (Messaging.LIBOBJC_DYLIB, EntryPoint = "objc_msgSend")] - extern static IntPtr IntPtr_objc_msgSend_IntPtr_IntPtr_IntPtr_IntPtr_IntPtr_IntPtr_IntPtr_IntPtr_IntPtr_IntPtr_IntPtr (IntPtr receiver, IntPtr selector, IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr arg4, System.IntPtr arg5, System.IntPtr arg6, System.IntPtr arg7, System.IntPtr arg8, System.IntPtr arg9, System.IntPtr arg10, System.IntPtr arg11); #endif const string selAppearanceForTraitCollection = "appearanceForTraitCollection:"; - /// To be added. - /// To be added. - /// Returns an appearance proxy for the specified . - /// To be added. - /// To be added. + /// Gets the appearance proxy for a class with the specified trait collection. + /// The Objective-C class pointer for the type to get the appearance proxy for. + /// The for which to return the appearance proxy. + /// The appearance proxy for the specified class and traits. public static IntPtr GetAppearance (IntPtr class_ptr, UITraitCollection traits) { - if (traits is null) - throw new ArgumentNullException ("traits"); + ArgumentNullException.ThrowIfNull (traits); IntPtr result = Messaging.IntPtr_objc_msgSend_IntPtr (class_ptr, Selector.GetHandle (UIAppearance.selAppearanceForTraitCollection), traits.Handle); GC.KeepAlive (traits); diff --git a/tests/cecil-tests/Documentation.KnownFailures.txt b/tests/cecil-tests/Documentation.KnownFailures.txt index 9333b1029ed0..f8be0d4acabb 100644 --- a/tests/cecil-tests/Documentation.KnownFailures.txt +++ b/tests/cecil-tests/Documentation.KnownFailures.txt @@ -16949,8 +16949,6 @@ M:UIKit.UIAlertView.remove_Presented(System.EventHandler) M:UIKit.UIAlertView.remove_WillDismiss(System.EventHandler{UIKit.UIButtonEventArgs}) M:UIKit.UIAlertView.remove_WillPresent(System.EventHandler) M:UIKit.UIAlertView.UIAlertViewAppearance.#ctor(System.IntPtr) -M:UIKit.UIAppearance.op_Equality(UIKit.UIAppearance,UIKit.UIAppearance) -M:UIKit.UIAppearance.op_Inequality(UIKit.UIAppearance,UIKit.UIAppearance) M:UIKit.UIApplication_DefaultApplication.GetDefaultStatus(UIKit.UIApplication,UIKit.UIApplicationCategory,Foundation.NSError@) M:UIKit.UIApplication.AccessibilityActivate M:UIKit.UIApplication.Dispose(System.Boolean) diff --git a/tests/dotnet/UnitTests/expected/iOS-MonoVM-interpreter-size.txt b/tests/dotnet/UnitTests/expected/iOS-MonoVM-interpreter-size.txt index 6d966d8a337b..57eca63962db 100644 --- a/tests/dotnet/UnitTests/expected/iOS-MonoVM-interpreter-size.txt +++ b/tests/dotnet/UnitTests/expected/iOS-MonoVM-interpreter-size.txt @@ -1,14 +1,14 @@ -AppBundleSize: 3,611,965 bytes (3,527.3 KB = 3.4 MB) +AppBundleSize: 3,597,600 bytes (3,513.3 KB = 3.4 MB) # The following list of files and their sizes is just informational / for review, and isn't used in the test: _CodeSignature/CodeResources: 3,997 bytes (3.9 KB = 0.0 MB) archived-expanded-entitlements.xcent: 384 bytes (0.4 KB = 0.0 MB) -Info.plist: 1,163 bytes (1.1 KB = 0.0 MB) -Microsoft.iOS.dll: 151,040 bytes (147.5 KB = 0.1 MB) +Info.plist: 1,150 bytes (1.1 KB = 0.0 MB) +Microsoft.iOS.dll: 150,528 bytes (147.0 KB = 0.1 MB) PkgInfo: 8 bytes (0.0 KB = 0.0 MB) runtimeconfig.bin: 1,405 bytes (1.4 KB = 0.0 MB) -SizeTestApp: 2,404,544 bytes (2,348.2 KB = 2.3 MB) +SizeTestApp: 2,390,688 bytes (2,334.7 KB = 2.3 MB) SizeTestApp.dll: 7,680 bytes (7.5 KB = 0.0 MB) -System.Private.CoreLib.aotdata.arm64: 41,296 bytes (40.3 KB = 0.0 MB) +System.Private.CoreLib.aotdata.arm64: 41,312 bytes (40.3 KB = 0.0 MB) System.Private.CoreLib.dll: 987,136 bytes (964.0 KB = 0.9 MB) System.Runtime.dll: 5,120 bytes (5.0 KB = 0.0 MB) System.Runtime.InteropServices.dll: 8,192 bytes (8.0 KB = 0.0 MB) diff --git a/tests/dotnet/UnitTests/expected/iOS-MonoVM-size.txt b/tests/dotnet/UnitTests/expected/iOS-MonoVM-size.txt index e9b92899cb31..5f58268179d0 100644 --- a/tests/dotnet/UnitTests/expected/iOS-MonoVM-size.txt +++ b/tests/dotnet/UnitTests/expected/iOS-MonoVM-size.txt @@ -1,14 +1,14 @@ -AppBundleSize: 9,362,185 bytes (9,142.8 KB = 8.9 MB) +AppBundleSize: 9,320,060 bytes (9,101.6 KB = 8.9 MB) # The following list of files and their sizes is just informational / for review, and isn't used in the test: _CodeSignature/CodeResources: 5,229 bytes (5.1 KB = 0.0 MB) aot-instances.aotdata.arm64: 827,592 bytes (808.2 KB = 0.8 MB) archived-expanded-entitlements.xcent: 384 bytes (0.4 KB = 0.0 MB) -Info.plist: 1,163 bytes (1.1 KB = 0.0 MB) +Info.plist: 1,150 bytes (1.1 KB = 0.0 MB) Microsoft.iOS.aotdata.arm64: 22,872 bytes (22.3 KB = 0.0 MB) Microsoft.iOS.dll: 48,640 bytes (47.5 KB = 0.0 MB) PkgInfo: 8 bytes (0.0 KB = 0.0 MB) runtimeconfig.bin: 1,481 bytes (1.4 KB = 0.0 MB) -SizeTestApp: 7,260,640 bytes (7,090.5 KB = 6.9 MB) +SizeTestApp: 7,218,528 bytes (7,049.3 KB = 6.9 MB) SizeTestApp.aotdata.arm64: 1,456 bytes (1.4 KB = 0.0 MB) SizeTestApp.dll: 7,168 bytes (7.0 KB = 0.0 MB) System.Private.CoreLib.aotdata.arm64: 640,736 bytes (625.7 KB = 0.6 MB) diff --git a/tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt b/tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt index 3735c88837b0..469468c38512 100644 --- a/tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt +++ b/tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt @@ -1,8 +1,8 @@ -AppBundleSize: 2,450,656 bytes (2,393.2 KB = 2.3 MB) +AppBundleSize: 2,436,531 bytes (2,379.4 KB = 2.3 MB) # The following list of files and their sizes is just informational / for review, and isn't used in the test: _CodeSignature/CodeResources: 2,589 bytes (2.5 KB = 0.0 MB) archived-expanded-entitlements.xcent: 384 bytes (0.4 KB = 0.0 MB) -Info.plist: 1,163 bytes (1.1 KB = 0.0 MB) +Info.plist: 1,150 bytes (1.1 KB = 0.0 MB) PkgInfo: 8 bytes (0.0 KB = 0.0 MB) runtimeconfig.bin: 1,808 bytes (1.8 KB = 0.0 MB) -SizeTestApp: 2,444,704 bytes (2,387.4 KB = 2.3 MB) +SizeTestApp: 2,430,592 bytes (2,373.6 KB = 2.3 MB) From 5cbf90c42e4028782130da4a63048c63afd9f352 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 2 Feb 2026 09:19:57 +0100 Subject: [PATCH 2/2] Update sizes. --- .../UnitTests/expected/iOS-MonoVM-interpreter-size.txt | 6 +++--- tests/dotnet/UnitTests/expected/iOS-MonoVM-size.txt | 6 +++--- tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/dotnet/UnitTests/expected/iOS-MonoVM-interpreter-size.txt b/tests/dotnet/UnitTests/expected/iOS-MonoVM-interpreter-size.txt index 57eca63962db..b31e62171bd7 100644 --- a/tests/dotnet/UnitTests/expected/iOS-MonoVM-interpreter-size.txt +++ b/tests/dotnet/UnitTests/expected/iOS-MonoVM-interpreter-size.txt @@ -1,12 +1,12 @@ -AppBundleSize: 3,597,600 bytes (3,513.3 KB = 3.4 MB) +AppBundleSize: 3,611,466 bytes (3,526.8 KB = 3.4 MB) # The following list of files and their sizes is just informational / for review, and isn't used in the test: _CodeSignature/CodeResources: 3,997 bytes (3.9 KB = 0.0 MB) archived-expanded-entitlements.xcent: 384 bytes (0.4 KB = 0.0 MB) -Info.plist: 1,150 bytes (1.1 KB = 0.0 MB) +Info.plist: 1,160 bytes (1.1 KB = 0.0 MB) Microsoft.iOS.dll: 150,528 bytes (147.0 KB = 0.1 MB) PkgInfo: 8 bytes (0.0 KB = 0.0 MB) runtimeconfig.bin: 1,405 bytes (1.4 KB = 0.0 MB) -SizeTestApp: 2,390,688 bytes (2,334.7 KB = 2.3 MB) +SizeTestApp: 2,404,544 bytes (2,348.2 KB = 2.3 MB) SizeTestApp.dll: 7,680 bytes (7.5 KB = 0.0 MB) System.Private.CoreLib.aotdata.arm64: 41,312 bytes (40.3 KB = 0.0 MB) System.Private.CoreLib.dll: 987,136 bytes (964.0 KB = 0.9 MB) diff --git a/tests/dotnet/UnitTests/expected/iOS-MonoVM-size.txt b/tests/dotnet/UnitTests/expected/iOS-MonoVM-size.txt index 5f58268179d0..dc3acfb5ca4e 100644 --- a/tests/dotnet/UnitTests/expected/iOS-MonoVM-size.txt +++ b/tests/dotnet/UnitTests/expected/iOS-MonoVM-size.txt @@ -1,14 +1,14 @@ -AppBundleSize: 9,320,060 bytes (9,101.6 KB = 8.9 MB) +AppBundleSize: 9,362,182 bytes (9,142.8 KB = 8.9 MB) # The following list of files and their sizes is just informational / for review, and isn't used in the test: _CodeSignature/CodeResources: 5,229 bytes (5.1 KB = 0.0 MB) aot-instances.aotdata.arm64: 827,592 bytes (808.2 KB = 0.8 MB) archived-expanded-entitlements.xcent: 384 bytes (0.4 KB = 0.0 MB) -Info.plist: 1,150 bytes (1.1 KB = 0.0 MB) +Info.plist: 1,160 bytes (1.1 KB = 0.0 MB) Microsoft.iOS.aotdata.arm64: 22,872 bytes (22.3 KB = 0.0 MB) Microsoft.iOS.dll: 48,640 bytes (47.5 KB = 0.0 MB) PkgInfo: 8 bytes (0.0 KB = 0.0 MB) runtimeconfig.bin: 1,481 bytes (1.4 KB = 0.0 MB) -SizeTestApp: 7,218,528 bytes (7,049.3 KB = 6.9 MB) +SizeTestApp: 7,260,640 bytes (7,090.5 KB = 6.9 MB) SizeTestApp.aotdata.arm64: 1,456 bytes (1.4 KB = 0.0 MB) SizeTestApp.dll: 7,168 bytes (7.0 KB = 0.0 MB) System.Private.CoreLib.aotdata.arm64: 640,736 bytes (625.7 KB = 0.6 MB) diff --git a/tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt b/tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt index 469468c38512..aa194e22ad61 100644 --- a/tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt +++ b/tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt @@ -1,8 +1,8 @@ -AppBundleSize: 2,436,531 bytes (2,379.4 KB = 2.3 MB) +AppBundleSize: 2,450,653 bytes (2,393.2 KB = 2.3 MB) # The following list of files and their sizes is just informational / for review, and isn't used in the test: _CodeSignature/CodeResources: 2,589 bytes (2.5 KB = 0.0 MB) archived-expanded-entitlements.xcent: 384 bytes (0.4 KB = 0.0 MB) -Info.plist: 1,150 bytes (1.1 KB = 0.0 MB) +Info.plist: 1,160 bytes (1.1 KB = 0.0 MB) PkgInfo: 8 bytes (0.0 KB = 0.0 MB) runtimeconfig.bin: 1,808 bytes (1.8 KB = 0.0 MB) -SizeTestApp: 2,430,592 bytes (2,373.6 KB = 2.3 MB) +SizeTestApp: 2,444,704 bytes (2,387.4 KB = 2.3 MB)