Is there a better way to serialize plist-y objects in Objective-C?

I like the ability to serialize plist for small collections of objects: it's simple, storage is XML, etc. But I believe that the values ​​of the settings in the dictionaries are cumbersome:

[myDict setObject:keepThis forKey:@"ivar"];

I would prefer to use an object derived from classes (or even just structures):

myObj.ivar = keepThis

... and then send a message to the collection to get a plist. The classes / structures used for this purpose may be limited so that they can directly and easily display primitives of primitives; for example, myObj can be mapped to NSDictionary, and the requirement can be placed on ivars, so they are one of the plist primitives.

Has someone already built a tool for this, or do I need to minimize it?

+3
source share
5 answers

I saw it elsewhere, but that is exactly what I was looking for. The answers above indicate raw ingredients, but here it is, all wrapped up: http://retaincount.com/blog/?p=7

0
source

I'm not sure that this is exactly what you are talking about, but Key Value Coding , among many other things, let you get a dictionary with values ​​from the instance data , and also set the instance data from the dictionary .

, , , . ( , , , , .) EDIT 2 2011: -[NSObject attributeKeys] iOS. , Mac, , .

(NSCoding - / , , XML, - / , , .)

+5

, SO, ivars .

+3

. Objective-C 2.0 :

objc_property_t *class_copyPropertyList(Class cls, unsigned int *outCount)

NSObject , .

+2

To use this property, you need to have a predefined set of possible keys. You cannot use arbitrary names using dot syntax - this must be a known property or accessory of the first operand. Thus, there cannot be a general form of this. But if you make your own, turning into a dictionary is as easy as making [self dictionaryWithValuesForKeys:listOfProperties].

0
source

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


All Articles