Bug 24125 - NSArray Count return nuint and GetItem<T>() accepts nint
Summary: NSArray Count return nuint and GetItem<T>() accepts nint
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: master
Hardware: PC Mac OS
: --- enhancement
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-10-29 03:12 UTC by David Karlaš
Modified: 2014-10-29 16:05 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description David Karlaš 2014-10-29 03:12:51 UTC
If user writes this code:
var nsArray = new NSArray();
for(nuint i = 0; i < nsArray.Count; i++)
{
  nsArray.GetItem<T>(i);
}
It doesn't work because it reports:"Error CS1502: The best overloaded method match for `Foundation.NSArray.GetItem<Foundation.NSObject>(System.nint)' has some invalid arguments"

If user changes "for(nuint i" to "for(int i" which is what most user do automatically(they are used to "for(int i") he gets "Error CS0034: Operator `<' is ambiguous on operands of type `int' and `System.nuint'" notice that int<uint works for example even for(int i=0;i<uint.MaxValue;i++) works but it reports warning because uint.MaxValue is out of range constant but still compiles(no warning is reported if list.Count is uint).

If user changes "for(nuint i" to "for(nint i" he gets "Error CS0034: Operator `<' is ambiguous on operands of type `System.nint' and `System.nuint'"

So here are 2 possible solutions. Solve problem just for NSArray but changing .Count or .GetItem<T>. Or implement Operator `<' between nint and nuint like they are between int and uint if this is possible...

Solution I'm ussing atm is this:
var nsArray = new NSArray();
for(nuint i = 0; i < nsArray.Count; i++)
{
  nsArray.GetItem<T>((nint)i);//Notice typecast
}
Comment 1 Sebastien Pouliot 2014-10-29 12:00:22 UTC
GetItem<T> ends up doing a call to

> - (id)objectAtIndex:(NSUInteger)index

so it makes sense to have it accept an `nuint` and be consistent with the rest of API.
Comment 2 Sebastien Pouliot 2014-10-29 16:05:27 UTC
Fixed in master / c7a0fb8ec7bad925ff66e325ada06bf668c81613