Re: Questions on using using modal sheets with Core Data
Re: Questions on using using modal sheets with Core Data
- Subject: Re: Questions on using using modal sheets with Core Data
- From: Kevin Ross <email@hidden>
- Date: Sun, 14 Jun 2009 18:31:50 -0700
I'm able to get the dependent values to update correctly if I access
the deepest path of the relationship before I set the value that will
cause them to update.
It seems like kind of a kludge, but it might be the best I can do
right now until I can ferret out a possible missed dependency somewhere.
Thanks for the tips!
Kevin
On Jun 12, 2009, at 12:55 PM, Kevin Ross wrote:
Thanks Dave,
I'm creating a new MOC in the sheet and hooking it up to the same
persistent store as the document, so when the NSArrayController
performs it's initial fetch at load (I have it set in IB to
automatically prepare content). I'm not actually using this context
to add or remove any entities, only changing the properties. Each
selectable managed object (an instance of FloorPlanMO) in the
NSArrayController has a 1-1 relationship with an entity called
FlyingStarsMO. This entity has 4 integer attributes that are
dependent upon values in the FloorPlanMO as well as some of the
values being inter-dependent amongst themselves. Here is the code
for the keyPathsForValuesAffectingKeys: of the FlyingStarMO. The
only value that I'm changing in this sheet is located at
@"floorPlan.house.yearOfLastMajorRenovation". I'm only changing the
integer value, not adding or deleting anything.
+ (NSSet *)keyPathsForValuesAffectingMountainStar; {
return [NSSet setWithObjects:@"floorPlan.sittingDirection",
@"floorPlan.facingDirection", @"loShuAgeStar", @"floorPlan",
@"floorPlan.house.yearOfLastMajorRenovation", nil];
}
+ (NSSet *)keyPathsForValuesAffectingWaterStar; {
return [NSSet setWithObjects:@"floorPlan.sittingDirection",
@"floorPlan.facingDirection", @"loShuAgeStar", @"floorPlan",
@"floorPlan.house.yearOfLastMajorRenovation", nil];
}
+ (NSSet *)keyPathsForValuesAffectingLoShuAgeStar; {
return [NSSet
setWithObjects:@"floorPlan.house.yearOfLastMajorRenovation", nil];
}
+ (NSSet *)keyPathsForValuesAffectingAnnualStar; {
return [NSSet
setWithObjects:@"floorPlan.house.yearOfLastMajorRenovation", nil];
}
+ (NSSet *)keyPathsForValuesAffectingStarChart; {
return [NSSet setWithObjects:@"mountainStar", @"annualStar",
@"waterStar", @"loShuAgeStar", nil];
}
The strange thing is that if I select all of the objects in the
NSArrayController first, and then change the value of
yearOfLastMajorRenovation, all the values in the StarChartMO get
updated in each FloorPlanMO like I want. But only after I've
selected the objects in the array controller first. From then on
all is well and each FloorPlanMO in the NSArrayController gets
updated when the yearOfLastMajorRenovation changes.
Everything updates fine when the arrayController is bound to the
document's MOC, but not when bound from the sheet's MOC. I'm going
back and checking to make sure I have all my dependencies accounted
for in keyPathsForValuesAffectingKeys:. Perhaps something isn't
being accounted for but was hidden because of the inter-dependencies?
Thanks again for taking the time to read this, and I need to provide
more information just let me know.
Kevin
On Jun 12, 2009, at 12:03 PM, Dave Fernandes wrote:
Kevin,
You'll have to say a bit more about how you adapted the example. Do
you create a new MOC and create new objects within it with
attributes copied from the document MOC? Is there a Core Data
relationship between these two new objects? What do you mean by
"dependent on others" and "propogated"? Is there some KVO
dependence, or have you defined
keyPathsForValuesAffectingValueForKey: or used the deprecated
setKeys:triggerChangeNotificationsForDependentKey:?
Dave
On Jun 12, 2009, at 12:59 PM, Kevin Ross wrote:
I adapted the examples in the NSPersistentDocument tutorial, and
this works great. The problem I'm having is with some of the
state management because some of the properties are dependent upon
others. I'll try to explain how the relationship works.
Let's say we have 2 objects in the sheet's MOC. When the sheet is
first opened, the selected object of the arrayController is fully
fetched and realized, but the second object hasn't fetched the
values from the MOC yet, so it's values aren't updated with the
first object when I change some of the parameters. If I select
each object first to fetch the properties from the backing-store,
then when I change a value it is immediately propagated as it
should. Do I have to try and access the values programmatically
so the objects become fully realized before I display the sheet?
I have the controller set to automatically prepare content, should
I turn that off and manually perform the fetches?
Thanks for your time,
Kevin
On Jun 11, 2009, at 8:31 PM, Dave Fernandes wrote:
This is explained in the NSPersistentDocument tutorial in the docs.
On Jun 11, 2009, at 10:03 PM, Kevin Ross wrote:
Hi all, have a Core Data document based application which uses
modal sheets as a way for the user to edit the document's data.
What is the best way to give the sheet the ability to operate on
a copy of the data with the parents sheet's undo context? And
how best to merge these changes with the main document context.
I've thought of having a unique MOC for each sheet, and then
posting a custom notification that would in turn cause each MOC
to perform something like:
for (id object in [managedObjectContext registeredObjects]) {
[managedObjectContext refreshObject:object
mergeChanges:YES];
}
Does this way make any sense? Is there a better way to do this
that I'm missing?
Thanks for any pointers!
Kevin
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the
list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden