xmartlabs/XLForm — pull request #34 by gulsharan-pv (2014-05-18 22:58:36+00:00)
Title: Extended XLFormSelectorCell to support non-primitive objects as option values

Here's some sample code to illustrate the change:

XLFormSectionDescriptor *section = [XLFormSectionDescriptor formSectionWithTitle:@"Dependent Info"];
[formDescriptor addFormSection:section];

row = [XLFormRowDescriptor formRowDescriptorWithTag:nil rowType:XLFormRowDescriptorTypeSelectorPush title:@"Relation to you"];
row.selectorOptions = @[[XLFormOptionsObject formOptionsObjectWithValue:[[CustomNameCodePair alloc] initWithName:@"Spouse" code:@"D0001"] displayText:@"Spouse"],
[XLFormOptionsObject formOptionsObjectWithValue:[[CustomNameCodePair alloc] initWithName:@"Parent" code:@"D0002"] displayText:@"Parent"],
[XLFormOptionsObject formOptionsObjectWithValue:[[CustomNameCodePair alloc] initWithName:@"Sibling" code:@"D0003"] displayText:@"Sibling"],
[XLFormOptionsObject formOptionsObjectWithValue:[[CustomNameCodePair alloc] initWithName:@"Child" code:@"D0004"] displayText:@"Child"]
];
row.value = dependent.relation; // CustomNameCodePair object
[section addFormRow:row];

Here's my CustomNameCodePair class implementation:

@implementation CustomNameCodePair

-(id) initWithName:(NSString *)name code:(NSString *)code {
self = [super init];
if (self) {
self.name = name;
self.code = code;
}

return self;
}

#pragma mark - hash and isEqual implementations

-(NSUInteger)hash {
return self.code.hash;
}

-(BOOL)isEqual:(id)object {
if (object == nil || ![object isKindOfClass:[CustomNameCodePair class]])
return NO;

return [self.code isEqual:((CustomNameCodePair *)object).code];
}

#pragma mark - toString() implementation

-(NSString *)displayText {
return self.name;
}

@end