An iteration has many stories. I just started with the Core Data sample, added a project entity, renamed Task to Iteration and TaskStep to Story
and added relationships from project to stories and project to iterations.
- (void)viewDidLoad {
[super viewDidLoad];
// Set up the edit and add buttons.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
// Create a class definition for Story
SCClassDefinition *storyDef =
[SCClassDefinition definitionWithEntityName:@"Story" withManagedObjectContext:self.managedObjectContext
withPropertyNames: [NSArray arrayWithObjects:@"name", @"desc",@"iteration", nil]];
// Create a class definition for Iteration
SCClassDefinition *iterationDef =
[SCClassDefinition definitionWithEntityName:@"Iteration" withManagedObjectContext:self.managedObjectContext
withPropertyNames: [NSArray arrayWithObjects:@"name", @"desc", @"dueDate", @"active", @"priority",
@"category", @"stories", nil]];
// Do some property definition customization
SCPropertyDefinition *storyPropertyDef = [storyDef propertyDefinitionWithName:@"desc"];
storyPropertyDef.title = @"Description";
storyPropertyDef.type = SCPropertyTypeTextView;
SCPropertyDefinition *iterationPropertyDef = [storyDef propertyDefinitionWithName:@"iteration"];
// Here is the problem.
// How do I define the attributes.
// This cannot work, as it doesn't know which iterations are allowed
//iterationPropertyDef.attributes = [SCObjectAttributes attributesWithObjectClassDefinition:iterationDef];
// Do some property definition customization
SCPropertyDefinition *descPropertyDef = [iterationDef propertyDefinitionWithName:@"desc"];
descPropertyDef.title = @"Description";
descPropertyDef.type = SCPropertyTypeTextView;
SCPropertyDefinition *priorityPropertyDef = [iterationDef propertyDefinitionWithName:@"priority"];
priorityPropertyDef.type = SCPropertyTypeSegmented;
priorityPropertyDef.attributes = [SCSegmentedAttributes
attributesWithSegmentTitlesArray:[NSArray arrayWithObjects:@"Low", @"Medium", @"High", nil]];
SCPropertyDefinition *categoryPropertyDef = [iterationDef propertyDefinitionWithName:@"category"];
categoryPropertyDef.type = SCPropertyTypeSelection;
categoryPropertyDef.attributes = [SCSelectionAttributes attributesWithItems:[NSArray arrayWithObjects:@"Home", @"Work", @"Other", nil]
allowMultipleSelection:NO
allowNoSelection:NO];
SCPropertyDefinition *storiesPropertyDef = [iterationDef propertyDefinitionWithName:@"stories"];
storiesPropertyDef.attributes = [SCArrayOfObjectsAttributes attributesWithObjectClassDefinition:storyDef
allowAddingItems:FALSE
allowDeletingItems:FALSE
allowMovingItems:TRUE];
// Create a class definition for Project
SCClassDefinition *projectDef =
// Do some property definition customization
[SCClassDefinition definitionWithEntityName:@"Project" withManagedObjectContext:self.managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"name",@"iterations",@"stories",nil]];
SCPropertyDefinition *iterationsPropertyDef = [projectDef propertyDefinitionWithName:@"iterations"];
iterationsPropertyDef.attributes = [SCArrayOfObjectsAttributes attributesWithObjectClassDefinition:iterationDef
allowAddingItems:TRUE
allowDeletingItems:TRUE
allowMovingItems:FALSE];
SCPropertyDefinition *projectStoriesPropertyDef = [projectDef propertyDefinitionWithName:@"stories"];
projectStoriesPropertyDef.attributes = [SCArrayOfObjectsAttributes attributesWithObjectClassDefinition:storyDef
allowAddingItems:TRUE
allowDeletingItems:FALSE
allowMovingItems:TRUE];
// Instantiate the tabel model
tableModel = [[SCTableViewModel alloc] initWithTableView:self.tableView withViewController:self];
// Create and add the objects section
SCArrayOfObjectsSection *objectsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil
withEntityClassDefinition:projectDef];
objectsSection.addButtonItem = self.navigationItem.rightBarButtonItem;
[tableModel addSection:objectsSection];
}