• 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
Re: Core Data: undo and non-object attribute [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data: undo and non-object attribute [SOLVED]


  • Subject: Re: Core Data: undo and non-object attribute [SOLVED]
  • From: Jakob Olesen <email@hidden>
  • Date: Sun, 15 Oct 2006 22:59:52 +0200


On 15/10/2006, at 21.36, Matteo Rossi wrote:

Remember, you still must call -willAccessValueForKey: and - didAccessValueForKey: before using your instance variables directly.

Just when I thought I had understood everything... If I'm not wrong, willAccessValueForKey should be used when the value could be stored in the persistent store and a fault should be fired to retrieve the correct value. Now, I have two persistent attributes xValue and yValue which are sync'ed to my ivars only in willSave and the updated values are in my ivars _point.x and _point.y. Why should I use willAccessValueForKey: and didAccessValueForKey: ? It's meaningful only for CD attributes which must be retrieved in the persistent store, I think. I've tried removing them in the accessors X and Y and everything seems to work fine.
Meanwhile I've run some tests to check real performances. The direct ivars access is definitely faster. If I can enable openGL Profiler I will post some specs.

Oh, dear. It sounds like you still have a bit of a mess.

I was hoping you had deleted all of the code you posted. You don't need it, and you don't need the transient attributes. They cannot help you with your structs. The section about non-standard attributes only deals with KVC-compliant values, i.e. objects and NSPoint, NSSize, NSRect, or NSRange.

What you want to do is to declare to perfectly normal persistent attributes x and y. If you want to store these in instance variables rather than the internal storage of NSManagedObject, you can do it in two ways:

1. Simply create two instance variables with the proper names:

@interface mybasic : NSManagedObject
{
	double x, y;
}

2. Keep your _point struct and implement primitive get/set accessors:

- (double)primitiveX
{
	return _point.x;
}

- (void)setPrimitiveX:(double)x
{
	_point.x = x;
}

That is all.

However, even with the values stored in instance variables, you cannot just use them like this:

- (double)sumBAD
{
	return _point.x + _point.y;
}

Blindingly fast as it may be, it doesn't fire faults, so the values may not be initialized. setPrimitiveX: is not called until the fault is fired. Using willAccessValueForKey: and -didAccessValueForKey: ensures that the instance variables have valid values. If your object happens to be faulted already, methods like sumBAD actually do work, but only as long as Core Data does not decide to turn the object back into a fault.

The code you posted is not any better in that respect. awakeFromFetch is also not called until the fault is fired.

I am not sure doing this is a good idea at all, in fact the documentation clearly states that it isn't.

I suppose you could write methods like sumBAD that only work once the fault has been fired, but you are playing with fire.

If you need seriously high-speed access to a list of points, you should copy them to an old-fashioned plain-old-data C array.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Core Data: undo and non-object attribute [SOLVED]
      • From: Matteo Rossi <email@hidden>
References: 
 >Core Data: undo and non-object attribute (From: Matteo Rossi <email@hidden>)
 >Re: Core Data: undo and non-object attribute (From: Jakob Olesen <email@hidden>)
 >Re: Core Data: undo and non-object attribute (From: Matteo Rossi <email@hidden>)
 >Re: Core Data: undo and non-object attribute (From: Jakob Olesen <email@hidden>)
 >Re: Core Data: undo and non-object attribute [SOLVED] (From: Matteo Rossi <email@hidden>)
 >Re: Core Data: undo and non-object attribute [SOLVED] (From: Jakob Olesen <email@hidden>)
 >Re: Core Data: undo and non-object attribute [SOLVED] (From: Matteo Rossi <email@hidden>)

  • Prev by Date: customizing NSCoding of NSDecimalNumber
  • Next by Date: Invisible App
  • Previous by thread: Re: Core Data: undo and non-object attribute [SOLVED]
  • Next by thread: Re: Core Data: undo and non-object attribute [SOLVED]
  • Index(es):
    • Date
    • Thread