Re: KVC, binding multiple properties, top level object
Re: KVC, binding multiple properties, top level object
- Subject: Re: KVC, binding multiple properties, top level object
- From: Graham Cox <email@hidden>
- Date: Mon, 14 Jul 2014 10:14:37 +1000
On 14 Jul 2014, at 7:29 am, Trygve Inda <email@hidden> wrote:
> Is NSInteger treated the same way? This page does not mention it:
NSInteger is a typedef for 'long', which size depends on the platform (32/64 bit), so valueForKey: will wrap it as a NSNumber using type 'long'. That's safe across archives that are used in both 32 and 64 bit ISAs, though with loss of precision if a 64-bit archive was dearchived on 32-bit (and this might become a permanent loss if the data is reachived and then opened in 64-bit). Scalar properties that explicitly declare 'long long' would be always 64-bit. I doubt if this is an issue in practice.
> NSNumber just seem a bit more flexible since they can be added to
> dictionaries (such as in the userInfo of a Notification).
Since - valueForKey: always returns an object, they too can be added to dictionaries.
I guess it's as broad as it's long, though my view would be that it's generally a better idea to take advantage of a framework feature where it exists (in this case, the auto wrapping and unwrapping of scalars) than roll your own solution which won't be as thoroughly debugged, take into account any corner cases, and so on. In this case it's also much less type safe. The auto-wrapping generally preserves type, or at least preserves precision (NSNumbers don't actually guarantee that a value's type won't change, e.g. a float that can be expressed as an integer will probably end up as an integer, but the point is there's no loss of precision).
--Graham
_______________________________________________
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