• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CoreData not noticing changes to transformable properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreData not noticing changes to transformable properties


  • Subject: CoreData not noticing changes to transformable properties
  • From: Jonathan del Strother <email@hidden>
  • Date: Fri, 3 Dec 2010 18:49:30 +0000

Hi,

I have an NSManagedObject with a transformable property
arrayOfWidgets, which is an NSArray of Widget instances, which
implement encodeWithCoder:

If I treat the Widget class as immutable, it all works fine : I assign
an NSArray of initialized widgets to arrayOfWidgets, and call save on
the managed object context.  -[Widget encodeWithCoder:] gets called,
my widgets are all persisted and load successfully the next time I
launch my app.

However, if I change a property of a widget after it's been saved,
it's extremely difficult to get CoreData to notice the change.  For
example (pseudocode):

self.arrayOfWidgets = [NSArray arrayWithObject:[Widget widgetWithName:@"Alf"]];
[self.managedObjectContext save:NULL];
// Successful save, arrayOfWidgets has 1 element with name Alf.

[[self.arrayOfWidgets lastObject] setName:@"Bob"];
[self.managedObjectContext save:NULL];
// CoreData doesn't notice this change, not entirely unexpectedly -
the persisted name is still Alf.

[[self.arrayOfWidgets lastObject] setName:@"Bob"];
self.arrayOfWidgets = [NSArray arrayWithObject:[self.arrayOfWidgets
lastObject]];
[self.managedObjectContext save:NULL];
// CoreData doesn't even notice this change, which seems bizarre given
I've assigned an entire new array to arrayOfWidgets.  Persisted name
is still Alf.

self.arrayOfWidgets = [NSArray arrayWithObject:[Widget widgetWithName:@"Bob"]];
[self.managedObjectContext save:NULL];
// CoreData finally notices the change - I have to basically
deep-clone the array, creating new instances all around, before the
persisted name changes to Bob.


Does that make sense?  Is there any way of sensibly dealing with
mutable objects in transformable CoreData attributes?

-Jonathan
_______________________________________________

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

  • Follow-Ups:
    • Re: CoreData not noticing changes to transformable properties
      • From: Adam Swift <email@hidden>
  • Prev by Date: Re: navigation bar tint color issue on iOS 4.2
  • Next by Date: Re: CoreData not noticing changes to transformable properties
  • Previous by thread: QT streaming with initWithAttributes
  • Next by thread: Re: CoreData not noticing changes to transformable properties
  • Index(es):
    • Date
    • Thread