I am writing an xml serialization class for objective-c.
The point is to give the class a class type and an XML file. It should return an instance with data.
This works for me, and it doesn’t work much - it processes primitives (+ nsstring), user classes and nsarrays. Does not handle pointers or C arrays.
Obviously, this is highly dependent on reflection.
Question: When I set the value of an instance of a certain class, should I check if the property with the correct name exists, or can I just set the variable with a simple reflection?
This is the code I've used so far:
id newClass = class_createInstance(NSClassFromString(elementName), sizeof(unsigned)); Ivar nameVar = class_getInstanceVariable([newClass class], "name"); if (nameVar != nil) object_setIvar(newClass, nameVar, [NSString stringWithString:@"George"]);
Also, after this kind of assignment, should I let go of something?
source share