Welcome, Guest
Username Password: Remember me

Nested Core Data Relationships
(1 viewing) (1) Guest

TOPIC: Nested Core Data Relationships

Nested Core Data Relationships 1 year, 7 months ago #1

Hi again,

Sorry for all the questions but trying to keep my head around the following relationshsip I have in Core Data and trying to map it too Sensible classes and property definitions. It is a bit similiar to your TaskStep sample but with an extra relationship.

An Inspection contains an array of InspectionArea objects. Each InspectionArea is defined as having an editable note associated with it and also contains the Area for which it is contained in. The predefined Area's have a predefined areaDescription. All are CoreData. I have removed some bits for clarity :

SCClassDefinition *inspectionDef = [SCClassDefinition definitionWithEntityName:@"Inspection" withManagedObjectContext:managedObjectContext withPropertyNames: [NSArray arrayWithObjects @"areas", nil] ];

SCClassDefinition *inspAreaClassDef =
[SCClassDefinition definitionWithEntityName:@"InspectionArea" withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"notes", @"areaDescription", nil]];
[inspAreaClassDef propertyDefinitionWithName:@"notes"].type = SCPropertyTypeTextView; //this is the editable field

SCPropertyDefinition *areaTypePropertyDef = [inspectionAreaClassDef propertyDefinitionWithName:@"areaDescription"];
areaTypePropertyDef.required = TRUE;
areaTypePropertyDef.type = SCPropertyTypeObjectSelection;
areaTypePropertyDef.attributes = [SCObjectSelectionAttributes attributesWithItemsEntityClassDefinition:areaDef
withItemsTitlePropertyName:@"areaDescription" allowMultipleSelection:NO allowNoSelection:NO];

SCPropertyDefinition *inspectorAreaPropertyDef = [inspectionDef propertyDefinitionWithName:@"areas"];
inspectorAreaPropertyDef.type = SCPropertyTypeArrayOfObjects;
inspectorAreaPropertyDef.attributes = [SCArrayOfObjectsAttributes attributesWithObjectClassDefinition:inspAreaClassDef allowAddingItems:YES allowDeletingItems:YES allowMovingItems:YES];


The problem is when I add an new Inspection Area, it only displays a field for the notes and there is no field or selection cell for the "AreaDescription". I must be doing something wrong but cant figure it out. Any help would be appreciated. Thanks
  • monsta
  • OFFLINE
  • Expert Boarder
  • Posts: 130
  • Karma: 2

Re: Nested Core Data Relationships 1 year, 7 months ago #2

No problem at all Phil, you can ask as many questions as you want

Your code seems to be perfectly fine. Are you sure you've set up your Core Data relationships correctly? Please send me the project to our support email if you like me to check them out for you.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Nested Core Data Relationships 1 year, 7 months ago #3

Have just send an email in to support. Thanks for looking at this.
  • monsta
  • OFFLINE
  • Expert Boarder
  • Posts: 130
  • Karma: 2

Re: Nested Core Data Relationships 1 year, 7 months ago #4

Thanks for sending it. Looking at your data model, I can't find an attribute called "areaDescription" in the InspectionArea entity, while you're declaring the entity's class definition with this attribute in the property names:

 
SCClassDefinition *inspAreaClassDef =
[SCClassDefinition definitionWithEntityName:@"InspectionArea"
withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"notes", @"areaDescription", nil]];
 


This explains why areaDescription is not showing in the generated STV model. Please tell me if you need any more help.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Nested Core Data Relationships 1 year, 7 months ago #5

Your spot on Tarek. Thanks for that. Working great now. However I seem to have a minor issue when adding a second InspectionArea. I can add one Inspection Area (by selecting an Area and then adding some notes) all ok, but when I goto add the second oneI receive this error :

2010-09-30 06:47:16.207 InspectionManager[41493:40b] -[Area compare:]: unrecognized selector sent to instance 0x5c88d40
2010-09-30 06:47:16.209 InspectionManager[41493:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Area compare:]: unrecognized selector sent to instance 0x5c88d40'
*** Call stack at first throw:
(
0 CoreFoundation 0x025fa919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x027485de objc_exception_throw + 47
2 CoreFoundation 0x025fc42b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0256c116 ___forwarding___ + 966
4 CoreFoundation 0x0256bcd2 _CF_forwarding_prep_0 + 50
5 Foundation 0x000f9bc5 _NSCompareObject + 76
6 CoreFoundation 0x02561b7f __CFSimpleMergeSort + 591
7 CoreFoundation 0x0256181c CFSortIndexes + 268
8 CoreFoundation 0x0259e574 CFMergeSortArray + 196
9 Foundation 0x000f98eb _sortedObjectsUsingDescriptors + 594
10 Foundation 0x000fc261 -[NSMutableArray(NSKeyValueSorting) sortUsingDescriptors:] + 499



I've got around it for now by adding my own compare method in the Area object, which seems to have fixed the problem. Not sure why that kind of exception is being raised though since the rest of the flow of the app is working ok.
  • monsta
  • OFFLINE
  • Expert Boarder
  • Posts: 130
  • Karma: 2

Re: Nested Core Data Relationships 1 year, 7 months ago #6

Hi!

I'm getting the same error message when i click the done button after adding my second item.

2010-10-02 20:13:57.840 MyApp[1170:207] -[Adresse compare:]: unrecognized selector sent to instance 0x5c7a5d0
2010-10-02 20:13:57.843 MyApp[1170:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Adresse compare:]: unrecognized selector sent to instance 0x5c7a5d0'
*** Call stack at first throw:
(
0 CoreFoundation 0x025cd919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0271b5de objc_exception_throw + 47
2 CoreFoundation 0x025cf42b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0253f116 ___forwarding___ + 966
4 CoreFoundation 0x0253ecd2 _CF_forwarding_prep_0 + 50
5 Foundation 0x000ccbc5 _NSCompareObject + 76
6 CoreFoundation 0x02534b7f __CFSimpleMergeSort + 591
7 CoreFoundation 0x0253481c CFSortIndexes + 268
8 CoreFoundation 0x02571574 CFMergeSortArray + 196
9 Foundation 0x000cc8eb _sortedObjectsUsingDescriptors + 594
10 Foundation 0x000cf261 -[NSMutableArray(NSKeyValueSorting) sortUsingDescriptors:] + 499
11 MyApp 0x0002e0c7 -[SCArrayOfObjectsSection tableViewControllerWillDisappear:cancelButtonTapped:doneButtonTapped:] + 1175
 


Thanks!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 149
  • Karma: 8
Time to create page: 1.08 seconds