NSManagedObjectContext - Key Value compliant

  • Using Xcode 2.4 Tiger 10.4.10 I had a subclass of an
    NSManagedObjectContext and used setValue and valueForKey on the extra
    ivars I had defined. Worked fine on Tiger PPC and Intel.  The compiled
    app failed to launch in Leopard.

    I have imported the project into XCode 3.0, Intel Leopard 10.0.  I
    have so far found that most (probably every) setValue:ForKey and
    valueForKey on any of the iVars for the subclassed Moc fails.  No
    message, no warning, not even when using the debugger, silence - and
    not going nowhere fast.

    Is this a bug or has there been a design change that I have missed.

    I can get-around it by adding glue code for each get and each set in
    the Moc subclass

    Can someone tell me which other Object Classes will exhibit this odd
    behaviour in Leopard.

    Keith
  • On Oct 28, 2007, at 3:04 AM, Keith Wilson wrote:

    > Using Xcode 2.4 Tiger 10.4.10 I had a subclass of an
    > NSManagedObjectContext and used setValue and valueForKey on the
    > extra ivars I had defined. Worked fine on Tiger PPC and Intel.  The
    > compiled app failed to launch in Leopard.
    >
    > I have imported the project into XCode 3.0, Intel Leopard 10.0.  I
    > have so far found that most (probably every) setValue:ForKey and
    > valueForKey on any of the iVars for the subclassed Moc fails.  No
    > message, no warning, not even when using the debugger, silence - and
    > not going nowhere fast.
    >

    To be clear, did you subclass NSManagedObject or NSManagedObjectContext?

    How are you creating the object?  Are you sure the object you are
    messaging is your subclass?

    > Is this a bug or has there been a design change that I have missed.
    >
    > I can get-around it by adding glue code for each get and each set in
    > the Moc subclass

    What do you mean by glue code?  Are you referring to accessors?

    If you really did subclass NSManagedObjectContext, note that the class
    docs "strongly discourage" that:

    http://developer.apple.com/documentation/Cocoa/Reference/CoreDataFramework/
    Classes/NSManagedObjectContext_Class/Reference/Reference.html#/

    /apple_ref/doc/uid/TP30001182

    It only refers to difficulties with change management and the undo
    manager, but from my own observations of Core Data, I suspect that is
    only the beginning of the complexities.

    I've been working with Core Data on Leopard for months and have not
    noticed any KVC problems, but I've never subclassed
    NSManagedObjectContext.

    Aaron
  • On Oct 28, 2007, at 12:04 AM, Keith Wilson wrote:

    > Using Xcode 2.4 Tiger 10.4.10 I had a subclass of an
    > NSManagedObjectContext and used setValue and valueForKey on the
    > extra ivars I had defined.

    NSManagedObjectContext is not designed to support subclassing.  In
    particular, you can't guarantee that every usage of
    NSManagedObjectContext within Core Data will be using an instance of
    your subclass; Core Data can create its own NSManagedObjectContext
    instances behind the scenes for various purposes, and if your custom
    managed objects expect their context to always be instances of your
    NSManagedObjectContext subclass, your code will fail.

    For example, think about how persistent store migration may be
    implemented.

    If at all possible, you'll want to rework your application or
    framework code to not rely on your subclass of
    NSManagedObjectContext.  It should work correctly on both Tiger and
    Leopard then.

    (I don't know that this would specifically cause the failure to
    launch, but since you didn't provide any console messages or
    backtraces that's all I can really go on.)

      -- Chris
  • > Using Xcode 2.4 Tiger 10.4.10 I had a subclass of an
    > NSManagedObjectContext and used setValue and valueForKey on the extra
    > ivars I had defined. Worked fine on Tiger PPC and Intel.  The compiled
    > app failed to launch in Leopard.

    You can file a bug report with bugreport.apple.com

    > I have imported the project into XCode 3.0, Intel Leopard 10.0.  I
    > have so far found that most (probably every) setValue:ForKey and
    > valueForKey on any of the iVars for the subclassed Moc fails.  No
    > message, no warning, not even when using the debugger, silence - and
    > not going nowhere fast.

    See the Key Value Coding documentation in the Foundation reference for
    the KVC protocol.  See the documentation for
    +accessInstanceVariablesDirectly

    <http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protoco
    ls/NSKeyValueCoding_Protocol/index.html#//apple_ref/doc/uid/TP40003780
    >

    > Is this a bug or has there been a design change that I have missed.

    It's a bug that a Tiger app does not run on Leopard.

    It's a design change that compiled against the 10.5 SDK this won't
    work.  Mean people were doing bad things with ivars that did not
    belong to them through KVC, and had to be punished (kinda joking).
    The problem was that through KVC people were getting at private state
    either without realizing it, or without fully appreciating how bad it
    was.  Come the end of the day, we all have to ship software, and we
    all write some pretty nasty hacks from time to time.  The point here
    is to force people to actually write the hacks, **which they know
    might not run on a future OS**, instead of allowing accidental binding
    to private state.

    > I can get-around it by adding glue code for each get and each set in
    > the Moc subclass

    That would be best.

    > Can someone tell me which other Object Classes will exhibit this odd
    > behaviour in Leopard.

    Any class can ask KVC to do this.  For Core Data classes,
    NSManagedObjectContext and NSManagedObjectID do (subclassing
    discouraged), but NSManagedObject does not (subclassing encouraged)

    - Ben
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today