CBRManagedObjectFormViewController 0.1.2

CBRManagedObjectFormViewController 0.1.2

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Oliver Letterer.



CBRManagedObjectFormViewController is a UITableViewController subclass to create and edit managed objects.

Usage

Let's take the following sample entity as a reference:

@interface SLEntity1 : NSManagedObject

@property (nonatomic, strong) NSNumber *dummyBool;

@property (nonatomic, strong) NSNumber *booleanValue;
@property (nonatomic, strong) NSString *stringValue;
@property (nonatomic, strong) NSDate *dateValue;

@property (nonatomic, strong) SLEntity2 *toOneRelation;
@property (nonatomic, strong) NSSet *toManyRelation;

@end

To setup and configure CBRManagedObjectFormViewController:

CBRManagedObjectFormViewController *viewController = [[CBRManagedObjectFormViewController alloc] initWithEntity:self.entity editingType:CBRManagedObjectFormViewControllerEditingTypeCreate];

/*
setup property mapping, keys are the attributes of the entity
and values their human readable representation which will be displayed to to user
*/
viewController.propertyMapping = @{
  @"booleanValue": NSLocalizedString(@"BOOL", @""),
  @"stringValue": NSLocalizedString(@"String", @""),
  @"dateValue": NSLocalizedString(@"Date", @""),
  @"dummyBool": NSLocalizedString(@"dummy", @""),
};

// setup completion handler
[self.viewController setCompletionHandler:^(BOOL didSaveEntity) {
  // called when done, dismiss view controller here
}];

Displaying data is organized in CBRManagedObjectFormViewController.sections:

@interface CBRManagedObjectFormViewControllerSection : NSObject <NSCopying>

+ (instancetype)staticSectionWithProperties:(NSArray *)properties;

+ (instancetype)staticSectionWithEnumValue:(NSArray *)enumValues humanReadableOptions:(NSArray *)humanReadableOptions forAttribute:(NSString *)attribute;

+ (instancetype)dynamicSectionWithRelationship:(NSString *)relationship
                      fetchedResultsController:(NSFetchedResultsController *)fetchedResultsController
                                   formatBlock:(NSString *(^)(id entity))formatBlock;

@end

Installation

Author

Oliver Letterer, [email protected]

License

CBRManagedObjectFormViewController is available under the MIT license. See the LICENSE file for more info.