WIP on API improvements for RKForm

This commit is contained in:
Blake Watters
2012-05-08 15:06:27 -04:00
parent b98e651efe
commit 81bcd17056
3 changed files with 29 additions and 2 deletions

View File

@@ -63,7 +63,7 @@ typedef void(^RKFormBlock)();
@property (nonatomic, readonly) NSArray *tableItems;
- (void)addSection:(RKFormSection *)section;
- (void)addSectionUsingBlock:(void (^)(RKFormSection *section))block;
- (void)addSectionUsingBlock:(void (^)(RKFormSection *section))block; // TODO: Eliminate this signature...
/** @name Single Section Forms */

View File

@@ -27,6 +27,7 @@
@property (nonatomic, readonly) id object;
+ (id)sectionInForm:(RKForm *)form;
+ (id)sectionUsingBlock:(void (^)(RKFormSection *))block;
- (id)initWithForm:(RKForm *)form;
- (void)addTableItem:(RKTableItem *)tableItem;
@@ -43,4 +44,6 @@
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)cellKeyPath onCellWithClass:(Class)cellClass;
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)cellKeyPath onCellWithClass:(Class)cellClass usingBlock:(void (^)(RKTableItem *tableItem))block;
- (void)addMappingFromAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)keyPath forTableItem:(RKTableItem *)tableItem;
@end

View File

@@ -29,8 +29,14 @@
return [[[self alloc] initWithForm:form] autorelease];
}
- (id)initWithForm:(RKForm *)form
+ (id)sectionUsingBlock:(void (^)(RKFormSection *))block
{
RKFormSection *section = [self section];
block(section);
return section;
}
- (id)initWithForm:(RKForm *)form {
self = [super init];
if (self) {
self.form = form;
@@ -117,8 +123,26 @@
[self addTableItem:tableItem];
}
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)controlKeyPath onControl:(UIControl *)control usingBlock:(void (^)(RKControlTableItem *tableItem))block {
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)controlKeyPath onControl:(UIControl *)control usingBlock:(void (^)(RKControlTableItem *tableItem))block
{
- (void)addMappingFromAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)keyPath forTableItem:(RKTableItem *)tableItem {
RKObjectAttributeMapping *attributeMapping = [[RKObjectAttributeMapping new] autorelease];
attributeMapping.sourceKeyPath = [NSString stringWithFormat:@"userData.__RestKit__object.%@", attributeKeyPath];
attributeMapping.destinationKeyPath = keyPath;
// TODO: This is duplicating code...
[tableItem.cellMapping addAttributeMapping:attributeMapping];
// Use KVC storage to associate the table item with object being mapped
// TODO: Move these to constants...
[tableItem.userData setValue:self.object forKey:@"__RestKit__object"];
[tableItem.userData setValue:attributeKeyPath forKey:@"__RestKit__attributeKeyPath"];
[tableItem.userData setValue:attributeMapping forKey:@"__RestKit__attributeToControlMapping"];
// [self addAttributeMapping:attributeMapping forKeyPath:attributeKeyPath toTableItem:tableItem];
}
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)controlKeyPath onControl:(UIControl *)control usingBlock:(void (^)(RKControlTableItem *tableItem))block {
RKControlTableItem *tableItem = [RKControlTableItem tableItemWithControl:control];
RKObjectAttributeMapping *attributeMapping = [[RKObjectAttributeMapping new] autorelease];
attributeMapping.sourceKeyPath = [NSString stringWithFormat:@"userData.__RestKit__object.%@", attributeKeyPath];