-
Notifications
You must be signed in to change notification settings - Fork 555
[UIKit] Enable nullability and clean up UICollectionView. #24599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This is file 5 of 30 files with nullability disabled in UIKit. * Enable nullability (#nullable enable). * Remove unused System.Threading.Tasks using directive. * Use ArgumentNullException.ThrowIfNull() instead of manual null checks. * Add nullable annotation for Source property (UICollectionViewSource?). * Simplify Source property getter with expression body. * Replace include file references with inlined XML documentation. * Remove inlined DocId entries from docs/api/UIKit/UICollectionView.xml. * Improve XML documentation comments: remove 'To be added.' placeholders, fix whitespace, add missing docs, add 'see cref' references. Contributes towards #17285.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Enables nullable reference types for UICollectionView and refreshes related API/documentation to reduce “nullable-disabled” surface area in UIKit.
Changes:
- Enabled
#nullableinsrc/UIKit/UICollectionView.csand updated signatures/docs (notablySourceand registration helpers). - Updated
ObjCRuntime.Class.GetHandleto accept nullableTypeand returnNativeHandle.Zerofor null. - Removed now-redundant XML DocId blocks from
docs/api/UIKit/UICollectionView.xmlafter inlining docs into source.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/UIKit/UICollectionView.cs | Enables nullability and updates helper APIs + XML docs for UICollectionView. |
| src/ObjCRuntime/Class.cs | Adjusts Class.GetHandle nullability/behavior to support nullable call sites. |
| docs/api/UIKit/UICollectionView.xml | Deletes DocId sections that are no longer referenced after doc inlining. |
| ArgumentNullException.ThrowIfNull (cellType); | ||
|
|
||
| RegisterClassForCell (Class.GetHandle (cellType), reuseIdentifier); |
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RegisterClassForCell (Type? cellType, NSString reuseIdentifier) declares cellType as nullable and the XML remarks explicitly say callers may pass null to un-register, but the method now throws via ArgumentNullException.ThrowIfNull (cellType). This makes the API contract inconsistent and prevents un-registration. Either allow null by removing the throw (and passing a zero handle), or make cellType non-nullable and update the remarks accordingly.
| ArgumentNullException.ThrowIfNull (cellType); | |
| RegisterClassForCell (Class.GetHandle (cellType), reuseIdentifier); | |
| var handle = cellType is null ? System.IntPtr.Zero : Class.GetHandle (cellType); | |
| RegisterClassForCell (handle, reuseIdentifier); |
| /// <param name="reuseIdentifier">A non-empty string to be associated with the <paramref name="cellType" />.</param> | ||
| /// <remarks> | ||
| /// <para>The <see cref="UICollectionView" /> maintains a highly-efficient reuse queue for offscreen components. This requires that the <see cref="UICollectionView" /> be responsible for the lifecycle management of its component views. This method (and related methods such as <see cref="RegisterClassForSupplementaryView(Type,UICollectionElementKindSection,string)" />) provide the <see cref="UICollectionView" /> the knowledge of which types it needs to instantiate.</para> | ||
| /// <para>The application developer may pass <see langword="null" /> as the <paramref name="reuseIdentifier" />, in which case the <paramref name="cellType" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another type, in which case the old type will be "de-registered" and the new <paramref name="cellType" /> will be used.</para> |
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The remarks say callers may pass null for reuseIdentifier, but reuseIdentifier is non-nullable here; based on the surrounding text this should refer to cellType instead. Please fix the XML documentation so it matches the actual parameters/behavior.
| /// <para>The application developer may pass <see langword="null" /> as the <paramref name="reuseIdentifier" />, in which case the <paramref name="cellType" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another type, in which case the old type will be "de-registered" and the new <paramref name="cellType" /> will be used.</para> | |
| /// <para>The application developer may pass <see langword="null" /> as the <paramref name="cellType" />, in which case the <paramref name="cellType" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another type, in which case the old type will be "de-registered" and the new <paramref name="cellType" /> will be used.</para> |
| /// <param name="reuseIdentifier">A non-empty string to be associated with the <paramref name="nib" />.</param> | ||
| /// <remarks> | ||
| /// <para>The <see cref="UICollectionView" /> maintains a highly-efficient reuse queue for offscreen components. This requires that the <see cref="UICollectionView" /> be responsible for the lifecycle management of its component views. This method (and related methods such as <see cref="RegisterNibForCell(UINib,string)" />) provide the <see cref="UICollectionView" /> the knowledge of which types it needs to instantiate.</para> | ||
| /// <para>The application developer may pass <see langword="null" /> as the <paramref name="reuseIdentifier" />, in which case the <paramref name="nib" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another nib, in which case the old nib will be "de-registered" and the new <paramref name="nib" /> will be used.</para> |
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The remarks state callers may pass null for reuseIdentifier, but reuseIdentifier is non-nullable; this appears to mean nib (which is nullable) can be null to un-register. Please correct the XML docs to avoid misleading API consumers.
| /// <para>The application developer may pass <see langword="null" /> as the <paramref name="reuseIdentifier" />, in which case the <paramref name="nib" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another nib, in which case the old nib will be "de-registered" and the new <paramref name="nib" /> will be used.</para> | |
| /// <para>The application developer may pass <see langword="null" /> as the <paramref name="nib" />, in which case the <paramref name="nib" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another nib, in which case the old nib will be "de-registered" and the new <paramref name="nib" /> will be used.</para> |
| public static NativeHandle GetHandle (Type? type) | ||
| { | ||
| if (type is null) | ||
| return NativeHandle.Zero; | ||
|
|
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class.GetHandle now accepts null and returns NativeHandle.Zero for null input, which is a behavioral change (previously null would fail). This can hide programming errors and may have broader impact beyond the intended un-registration scenarios. Consider keeping the existing throwing behavior and introducing a separate helper (or clearly documenting the new null->Zero behavior in the XML docs).
This is file 5 of 30 files with nullability disabled in UIKit.
Contributes towards #17285.