Bug 43444 - NSDimension.BaseUnit static method causes NSInvalidArgumentException
Summary: NSDimension.BaseUnit static method causes NSInvalidArgumentException
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.99 (iOS 10 previews)
Hardware: PC Mac OS
: Normal normal
Target Milestone: Xcode8 (iOS10)
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2016-08-17 00:37 UTC by Larry O'Brien
Modified: 2016-08-25 09:07 UTC (History)
3 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:
VERIFIED FIXED

Description Larry O'Brien 2016-08-17 00:37:56 UTC
OK, so I'm still using the previous binding where NSUnit/NSDimension/NSUnit{Foo} instead of Unit/Dimension/Unit{Foo} but putting that aside:

The new NSUnit/NSDimension/NSUnit{Foo} hierarchy has a method `BaseUnit` that is supposed to return: "An NSDimension subclass object from which all other units provided by the subclass are defined." and "The default implementation returns nil to indicate that the NSDimension class should not be used directly.

When implementing a subclass, you should return a unit converter that returns the inputted value for both the baseUnitValueFromValue: and valueFromBaseUnitValue: methods." 

So, for instance, in Swift you have:

   var au = UnitAcceleration.baseUnit()

And that gives you an instance of UnitAcceleration. 

We bind it as a static method, but when you run

   var au = NSUnitAcceleration.BaseUnit;

You get:

NSInvalidArgumentException "You must override baseUnit in your class NSDimension to define its base unit." 

(The issue is not unique to NSUnitAcceleration, of course...)
Comment 1 Sebastien Pouliot 2016-08-17 19:55:12 UTC
> where  NSUnit/NSDimension/NSUnit{Foo} instead of Unit/Dimension/Unit{Foo}

I'm not sure what you mean by the above, it seems you're comparing the ObjC vs the Swift API.

> BaseUnit

I'll check that. In ObjC you can override static "methods" which is not something you can do in C# and it requires a bit of extra code.
Comment 2 Sebastien Pouliot 2016-08-18 02:06:41 UTC
I got a local fix for NSUnitAcceleration - but it needs to be duplicated for other types (since it's _unnatural_ for C# to override static methods).

It's nice that you spotted this as it will need to be documented, i.e. how to handle `baseUnit` when subclassing `NSUnit` for your own types.


Also note that `NSDimension` will become `abstract` based on the comment

> NSDimension is an abstract subclass of NSUnit

from https://developer.apple.com/reference/foundation/nsdimension?language=objc
Comment 3 Sebastien Pouliot 2016-08-18 13:55:41 UTC
https://github.com/xamarin/xamarin-macios/pull/623
Comment 4 Sebastien Pouliot 2016-08-19 14:05:43 UTC
Fixed in xamarin-macios/xcode8 c7abd28f2c07407602080527b6b9486743af995b