SBeckett
SBeckett

Reputation: 31

CoreData NSArrayController addObject: Confusion

I am parsing an *.xml document that has two sections. Section One has summary data and Section Two has detailed data. I have two Data Entities who have a one to many relationship (one Summary Data entry has many Detailed Data entries associated with it). I also have two Table Views, one for the summary data and one for the detailed data. I have gone through all of the bindings (over and over) and do not get any error messages regarding the key value coding.

I want to, and can, put the summary data into the Summary Data Array Controller with the following code:

NSObject *newEntry = [controllerSummaryDataArray newObject];
[newEntry setValue:valueDate forKey:@"valueDate"];
[newEntry setValue:valueDuration forKey:@"valueDuration"];
[newEntry setValue:valueDistance forKey:@"valueDistance"];
[controllerSummaryDataArray addObject:newEntry];

Each time I import an *.xml file, the appropriate cells are updated in the Summary Data Table View as one would expect (this works whether or not the addObject method is called - which seems odd to me). When I add NSLog(@"The Duration Value is:", [newEntry valueForKey:@"valueDuration"]); it displays the appropriate value.

The difficulty I am having is the detailed data is not being inserted into the Detailed Data Array Controller. I am pulling the detailed data out of an interim array (due to the xmlParser and pre insertion calculations), so, the following code should do the trick.

for (rowCount = 0; rowCount < [arrayDetailData count]; rowCount++) {
    
    dataDetail = [arrayDetailData objectAtIndex:rowCount];

    NSObject *newDataEntry = [controllerDetailDataArray newObject];

    [newDataEntry setValue:[[NSNumber alloc] initWithFloat:[[dataDetail valueForKey:@"dataDuration"] intValue]] forKey:@"dataDuration"];

    [newDataEntry setValue:[[NSNumber alloc] initWithFloat:([[dataDetail valueForKey:@"dataSpeed"] intValue] * 0.0036)] forKey:@"dataSpeed"];
    
    [controllerDetailDataArray addObject:newDataEntry];
}

When I add:

 NSLog(@"The Array Value is %@ and the Controller Value is: %@", [dataDetail valueForKey:@"dataDuration"], [newDataEntry valueForKey:@"dataDuration"]);

...to the above for loop I get the appropriate Array Value and (NULL) for the Controller Value. I get the same results whether I use the interim array's values or hard coded values.

When saving the document to an *.xml file, I can see the Summary Data all nicely mapped out, complete with relationship name="dataDetail" type="0/0" destination="DATADETAIL" /relationship, however, there isn't any Detail Data (which one would expect because the data isn't being added to the Detail Data Array Controller).

Do I need to do something to tell the Detail Data ArrayController to accept objects that are linked to the Summary Data Array Controller? If so, how is that accomplished? If not, what am I doing wrong?

Update:

I found the problem. I didn't have the Detail Data Array Controller as a Referencing Outlet of File's Owner. Once I hooked that up, it works like a charm. Now if I could only keep it from using so much memory as it imports the data...

Upvotes: 1

Views: 719

Answers (1)

TechZen
TechZen

Reputation: 64428

You're not using Core Data. All Core Data objects are or inherit from NSManagedObject. You are just using generic (the most generic possible) NSObject instances and then assigning them keys and values using the associative storage functionality (this is like a dictionary attached to every object to which arbitrary keys and values can be assigned.)

So, you are not getting any management of the objects or the relationships between them.

Not sure exactly what you are trying to do.

Upvotes: 1

Related Questions