Finally I'm using STV again - and the first time in version 3.0.
Here's a sample of how it's being used:
model = [[SCTableViewModel alloc] initWithTableView:self.tableView]; // Hide the PREV/NEXT & DONE accessory view. model.inputAccessoryView = nil; SCUserDefaultsDefinition *userDefaultsDef = [SCUserDefaultsDefinition definitionWithDictionaryKeyNamesString:@":(email,password):Will be automatically signed in"]; if(self.isRegistration) { userDefaultsDef = [SCUserDefaultsDefinition definitionWithDictionaryKeyNamesString:@":(name,email,phone,password):"]; } SCUserDefaultsStore *userDefaultsStore = [SCUserDefaultsStore storeWithDefaultDataDefinition:userDefaultsDef]; [userDefaultsStore.standardUserDefaultsObject removeObjectForKey:@"email"]; [userDefaultsStore.standardUserDefaultsObject removeObjectForKey:@"password"]; if(self.isRegistration) { SCPropertyDefinition *firstNameDef = [userDefaultsDef propertyDefinitionWithName:@"displayName"]; firstNameDef.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath) { [cell becomeFirstResponder]; }; } SCPropertyDefinition *usernameDef = [userDefaultsDef propertyDefinitionWithName:@"email"]; usernameDef.attributes = [SCTextFieldAttributes attributesWithPlaceholder:nil secureTextEntry:NO autocorrectionType:UITextAutocorrectionTypeNo autocapitalizationType:UITextAutocapitalizationTypeNone]; usernameDef.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath) { SCTextFieldCell *textFieldCell = (SCTextFieldCell *)cell; textFieldCell.textField.keyboardType = UIKeyboardTypeEmailAddress; if(!self.isRegistration) { [cell becomeFirstResponder]; } }; usernameDef.cellActions.valueIsValid = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath) { BOOL valid = FALSE; if([cell isKindOfClass:[SCTextFieldCell class]]) { SCTextFieldCell *textFieldCell = (SCTextFieldCell *)cell; if([textFieldCell.textField.text length] > 4) valid = TRUE; textFieldCell.textLabel.textColor = valid ? [UIColor blackColor] : [UIColor redColor]; } return valid; }; SCPropertyDefinition *phoneDef = [userDefaultsDef propertyDefinitionWithName:@"phone"]; phoneDef.attributes = [SCTextFieldAttributes attributesWithPlaceholder:nil secureTextEntry:NO autocorrectionType:UITextAutocorrectionTypeNo autocapitalizationType:UITextAutocapitalizationTypeNone]; phoneDef.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath) { SCTextFieldCell *textFieldCell = (SCTextFieldCell *)cell; textFieldCell.textField.keyboardType = UIKeyboardTypePhonePad; }; SCPropertyDefinition *passwordDef = [userDefaultsDef propertyDefinitionWithName:@"password"]; passwordDef.attributes = [SCTextFieldAttributes attributesWithPlaceholder:nil secureTextEntry:YES autocorrectionType:UITextAutocorrectionTypeNo autocapitalizationType:UITextAutocapitalizationTypeNone]; passwordDef.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath) { SCTextFieldCell *tfc = (SCTextFieldCell *) cell; tfc.textField.returnKeyType = self.isRegistration ? UIReturnKeyNext : UIReturnKeySend; }; passwordDef.cellActions.valueIsValid = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath) { BOOL valid = FALSE; if([cell isKindOfClass:[SCTextFieldCell class]]) { SCTextFieldCell *textFieldCell = (SCTextFieldCell *)cell; if([textFieldCell.textField.text length] >= kMinimumPasswordLength) valid = TRUE; textFieldCell.textLabel.textColor = valid ? [UIColor blackColor] : [UIColor redColor]; } return valid; }; passwordDef.cellActions.returnButtonTapped = ^(SCTableViewCell *cell, NSIndexPath *indexPath) { [model commitChanges]; if(!model.valuesAreValid) { [SVProgressHUD showErrorWithStatus:@"Form incomplete"]; } else { [cell resignFirstResponder]; [SVProgressHUD showWithStatus:self.isRegistration ? @"Registering" : @"Logging in"]; if(self.isRegistration) { [self registerOnServer:@{ @"username" : [userDefaultsStore.standardUserDefaultsObject valueForKey:@"email"], @"email" : [userDefaultsStore.standardUserDefaultsObject valueForKey:@"email"], @"password" : [userDefaultsStore.standardUserDefaultsObject valueForKey:@"password"], @"displayName" : [userDefaultsStore.standardUserDefaultsObject valueForKey:@"name"], @"phone" : [userDefaultsStore.standardUserDefaultsObject valueForKey:@"phone"] }]; } else { [self loginUser:@{ @"username" : [userDefaultsStore.standardUserDefaultsObject valueForKey:@"email"], @"password" : [userDefaultsStore.standardUserDefaultsObject valueForKey:@"password"] }]; } } }; [model generateSectionsForUserDefaultsDefinition:userDefaultsDef];
I think that's quite a lot of code and quite a lot of functionality too. The question is: How would you optimize this and remove LOC, if possible?
(This question is not about a specific problem, I just like to know how the experts use this library). :-)
Best wishes,
Sebastian