• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSNumber : method to return pointer to represented value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumber : method to return pointer to represented value


  • Subject: Re: NSNumber : method to return pointer to represented value
  • From: "email@hidden" <email@hidden>
  • Date: Sun, 23 Feb 2014 09:30:08 +0000

On 23 Feb 2014, at 00:07, Graham Cox <email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSNumber : method to return pointer to represented value
      • From: email@hidden
    • Re: NSNumber : method to return pointer to represented value
      • From: Graham Cox <email@hidden>
    • Re: NSNumber : method to return pointer to represented value
      • From: Ken Thomases <email@hidden>
    • Re: NSNumber : method to return pointer to represented value
      • From: Graham Cox <email@hidden>
    • Re: NSNumber : method to return pointer to represented value
      • From: Graham Cox <email@hidden>
References: 
 >NSNumber : method to return pointer to represented value (From: "email@hidden" <email@hidden>)
 >Re: NSNumber : method to return pointer to represented value (From: Fritz Anderson <email@hidden>)
 >Re: NSNumber : method to return pointer to represented value (From: "email@hidden" <email@hidden>)
 >Re: NSNumber : method to return pointer to represented value (From: Ken Thomases <email@hidden>)
 >Re: NSNumber : method to return pointer to represented value (From: "email@hidden" <email@hidden>)
 >Re: NSNumber : method to return pointer to represented value (From: Ken Thomases <email@hidden>)
 >Re: NSNumber : method to return pointer to represented value (From: "email@hidden" <email@hidden>)
 >Re: NSNumber : method to return pointer to represented value (From: Graham Cox <email@hidden>)

  • Prev by Date: A possibly simpler way to do custom Core Data migration
  • Next by Date: Re: NSNumber : method to return pointer to represented value
  • Previous by thread: Re: NSNumber : method to return pointer to represented value
  • Next by thread: Re: NSNumber : method to return pointer to represented value
  • Index(es):
    • Date
    • Thread