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

> 
> You might find it happens to work today but it is not contracted to do so
> 
I agree that there is some uncertainty going forward.

Part of the issue I think is in the nature of class clusters.
We rely on the behaviour of an unspecified collection of private subclasses of 
a public abstract super class.
The public interface supplies the contract yet changes to the exact 
implementation of the private subclasses can affect how the contract is 
honoured (as the subclass is free to fulfil the public contract any way it 
likes.
This leads to the sort of concerns that have been put forward.

The NSNumbers docs say:

Note that number objects do not necessarily preserve the type they are created 
with.

and:

As with any class cluster, subclasses of NSNumber must override the primitive 
methods of its superclass, NSValue. In addition, there are two requirements 
around the data type your subclass represents:

        • Your implementation of objCType must return one of “c”, “C”, “s”, 
“S”, “i”, “I”, “l”, “L”, “q”, “Q”, “f”, and “d”. This is required for the other 
methods of NSNumber to behave correctly.
        • Your subclass must override the accessor method that corresponds to 
the declared type—for example, if your implementation of objCType returns “i”, 
you must override intValue.

The first is a logical cause for concern, but perhaps(!) it only becomes 
relevant in non primitive representations like NSDecimalNumber. 
The second provides some support for the idea that the NSNumber private 
subclasses do indeed return an invariant -objCType.
Ultimately clarity on the matter still eludes me. 

If I end up writing an NSNumber clone class cluster then at least I will now 
have a decent idea of what it may entail.
At present I am still wrangling with precisely what behaviour such a cluster 
would have.

>  1(int) and 1(float) can be represented by the same NSNumber object perfectly 
> legally.
Is that true?
Tagged pointers slipperiness. These are very private indeed.

(lldb) p na
(NSNumber *) $0 = 0x0000000000000127 (int)1
(lldb) p nb
(NSNumber *) $1 = 0x0000000100400b40 (float)1.000000

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