Re: PList Data Typing
Re: PList Data Typing
- Subject: Re: PList Data Typing
- From: Ken Thomases <email@hidden>
- Date: Mon, 15 Dec 2014 16:40:37 -0600
On Dec 15, 2014, at 4:10 PM, Kevin Bracey <email@hidden> wrote:
> I'm needing to read in a PList, that others have designed, I have no control over the input.
>
> One of the Keys stores either a String, Number or Boolean value.
>
> Checking for the NSString is straight forward.
>
> How can I tell if the Value is a Boolean or Number in the NSDictionary? as 0 and 1 are valid values for a number.
In Cocoa, both booleans and numbers are represented by NSNumber.
In Core Foundation, there are distinct types, CFBoolean and CFNumber.
NSNumber and CFNumber are toll-free bridged, but there's no similar guarantee about NSNumber and CFBoolean.
The most reliable solution may be to use Core Foundation to deserialize the property list. See CFPropertyList <https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFPropertyListRef/index.html>. For any given object in the resulting property list, you can check its type using the standard mechanism for CFTypes. Call CFGetTypeID() on the object and then compare the result to CFBooleanGetTypeID(), CFNumberGetTypeID(), etc.
Regards,
Ken
_______________________________________________
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