How does the JSONR representation of the NSDictionary class work?

some time ago, I figured out JSON handling in Objective-C (iPhone), and I found one confusing thing there.

This challenge puzzles me:

NSString* jsonString = [jsonDict JSONRepresentation]; 

In fact, jsonDict is an instance of the NSDictionary class and according to the NSDictionary class reference NSDictionary does not have this JSONRepresentation method. I feel cheated somewhere, I know that it works, but cannot figure out how.

Can anyone explain?

thanks

+6
source share
3 answers

This is an example of a β€œcategory”, which is a way to add methods to existing classes.

http://developer.apple.com/library/ios/#documentation/general/conceptual/DevPedia-CocoaCore/Category.html

+6
source

Take a look at the JSON Framework , this method came from.

+5
source

The frame places the category in an NSDictionary. Categories are used to add additional methods to the class. Additional information on how categories work is done in documents. Now that you know the right term for it, it's easy to find.

+3
source

Source: https://habr.com/ru/post/885615/


All Articles