Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ended up defining a method that recursively maps the properties to XML nodes if their names match. The naming convention and the data type of the property is important for this to work.</p> <p>I've tried my best to clean this up before I post it here, but let me know if you need any help.</p> <pre><code>- (RKObjectMapping *)mapMe:(Class)class { RKObjectManager *objectManager = [RKObjectManager sharedManager]; RKObjectMapping *mapping = [RKObjectMapping mappingForClass:class]; id classType = objc_getClass([NSStringFromClass(class) UTF8String]); unsigned int outCount, i; objc_property_t *properties = class_copyPropertyList(classType, &amp;outCount); for (i = 0; i &lt; outCount; i++) { objc_property_t property = properties[i]; // fprintf(stdout, "%s\n", property_getName(property)); const char *type = property_getAttributes(property); NSString *typeString = [NSString stringWithUTF8String:type]; NSArray *attributes = [typeString componentsSeparatedByString:@","]; // NSLog(@"attributes = %@", attributes); NSString *typeAttribute = [attributes objectAtIndex:0]; // NSLog(@"typeAttribute = %@", typeAttribute); NSString *propertyType = [typeAttribute substringFromIndex:1]; if ([propertyType hasPrefix:@"@"] &amp;&amp; [propertyType length] &gt; 1) { NSString * typeClassName = [propertyType substringWithRange:NSMakeRange(2, [propertyType length]-3)]; //turns @"NSDate" into NSDate Class typeClass = NSClassFromString(typeClassName); if (typeClass != nil &amp;&amp; ![typeClassName hasPrefix:@"NS"]) { // my custom class detected. RKObjectMapping *subMapping = [self mapMe:typeClass forObjectManager:objectManager]; [mapping mapRelationship:[NSString stringWithUTF8String:property_getName(property)] withMapping:subMapping]; [objectManager.mappingProvider setMapping:subMapping forKeyPath:[NSString stringWithUTF8String:property_getName(property)]]; } else { [mapping addAttributeMapping:[RKObjectAttributeMapping mappingFromKeyPath:[NSString stringWithFormat:@"%@.text", [NSString stringWithUTF8String:property_getName(property)]] toKeyPath:[NSString stringWithUTF8String:property_getName(property)]]]; } } } free(properties); return mapping; } </code></pre> <p>And then to map it automatically call it as:</p> <pre><code>[self mapMe:[Myclass class]]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload