Welcome, Guest
Username Password: Remember me

Core Data selecting instead of creating entities
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Core Data selecting instead of creating entities

Core Data selecting instead of creating entities 1 year, 8 months ago #1

I have a core data model with projects having stories and iterations.

Project has Stories
Project has Iterations
Story is assigned to Iteration (but only those from the project)

How do I set the class definition up so that the story's iteration always uses a selection?
  • Stephan
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
  • Karma: 1

Re: Core Data selecting instead of creating entities 1 year, 8 months ago #2

What is the relationship between stories and iterations? Is it one to one or one to many? Also, do you have any code for the story class definition that I can look at? Thanks.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Core Data selecting instead of creating entities 1 year, 8 months ago #3

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];
}
 
  • Stephan
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
  • Karma: 1

Re: Core Data selecting instead of creating entities 1 year, 8 months ago #4

Hi again Stephan,

You can achieve what you want by creating a detail view (appears when the iteration cell is tapped) that has an SCSelectionSection that gets its items from all available iterations.

Having said that, what you're requesting seems like a common functionality that many other users can benefit from, and therefore we will have this functionality added to the main release of Sensible TableView so that you could use it out of the box. With the new addition, STV will automatically create this detail view for you and will handle the selection assignment.

This new addition should require about three days of development, but if this is something urgent for you, please tell me and I can elaborate more on the solution I gave above.

Thanks a lot.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
Last Edit: 1 year, 8 months ago by tarekskr.

Re: Core Data selecting instead of creating entities 1 year, 8 months ago #5

Hello Tarek,

Yes, I thought it to be useful common functionality. Three days is really good turn-around. It is not that urgent, and I'll just try adding it myself for now. Thank you.
  • Stephan
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
  • Karma: 1

Re: Core Data selecting instead of creating entities 1 year, 8 months ago #6

On the other hand, it is something that's not yet described in the video's . I think I'd like the explanation, as I have a few custom views I need to connect later. But no need to hurry.
  • Stephan
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
  • Karma: 1
  • Page:
  • 1
  • 2
Time to create page: 1.22 seconds