Skip to content

A lightweight category for NSDictionary providing greater control of value lookup (with some coercion)

Notifications You must be signed in to change notification settings

bryanoltman/NSDictionary-TypedAccessors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

NSDictionary+TypedAccessors

This category builds upon NSDictionary's objectForKey: function to add more specific return types. If the value returned from objectForKey: is not of the desired type, this will attempt to coerce that value into the desired type.

I wrote this category because XML does not map directly to JSON. For example, most XML-to-JSON serializers would not convert XML collection with a single value into a JSON array. For example, this:

<omg-so-many-objects>
	<one-object>some-value</one-object>
</omg-so-many-objects>

gets converted to this:

omg-so-many-objects:some-value

instead of this:

omg-so-many-objects:[
	some-value
]

To solve this problem, you would use arrayForKey:, which would place some-value into an array.

All objects returned from functions in this category are autoreleasing, so this code works equally well with or without ARC.

About

A lightweight category for NSDictionary providing greater control of value lookup (with some coercion)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published