On 23 Feb 2014, at 00:07, Graham Cox <graham....@bigpond.com> wrote:

> NSNumber's can be slippery buggers, in my experience.
Won’t disagree with that.

> 
> Why are you so determined that you must use NSNumber, rather than your own 
> class? You haven't adequately explained why that isn't a good solution, as it 
> certainly sounds as if it would be, and cut through all the uncertainty and 
> bad fit of NSNumber for this purpose.
> 

I suppose I think that NSNumber actually is a good fit.
My usage model requires:

1. Configure an object with a numeric type: e.g.: @((int)5).
2. When I query an object subclass with getValue: I want to receive back an 
instance of the numeric content with a type as reported by -objCType.
3. For any given object subclass (of which there may be many) I want  -objCType 
to be constant.

I think that NSNumber does all of the above. Ken believes that 3. is in doubt.
If this proves to be the case then I will have to go down the custom class 
route.

Why the reluctance?
The objects represent numeric keys in C# dictionaries.
I can specialise them as such and have a NSKeyedNumber class.
But this level of specialisation does not occur in a NSDictionary so I am keen 
to keep things as clean as possible.

C# has a much wider class fauna that Cocoa and relies heavily on Interface 
usage.
Cocoa is much simpler by comparison.

Something of the nature of how tricky I have found this problem can be seen 
here (and thanks to everyone for having kept up the queries: my understanding 
of the problem/NSNumber is much better thanks to them):

This dict, when instantiated, will contain 1 key value pair.
    NSDictionary *dict = @{ @((int)1): @"val 1", @((float)1): @"val 2" };

However, this C# Dictionary<TKey, TValue> unit test object will contain two, 
            ObjectObjectDictionary = new Dictionary<object, object> {
               { 1, 8 },
                { 1F,  "Dubrovnik.UnitTests" },
            };

When I convert ObjectObjectDictionary to an NSDictionary  it will loose a key 
value pair (and that very fact may ultimately push me down a custom class 
route, but my insight into this isn’t good enough just yet).
However if I query the underlying object with  @((int)1) I will receive 8.
if I query the underlying object with  @((float)1) I will receive 
"Dubrovnik.UnitTests" .

Therefore the encoded class of the numeric key is essential.

This is something of an edge case. But that is what happens with unit tests.
You write what seems like a decent test and make is pass or just delete the 
test and pretend to yourself that you never thought of it!

I am now going to shut up.

Jonathan




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to