Core Data Problem

  • Hi All,

    I am a newbie ObjC/Cocoa programmer, and I have a small core data
    application that I am writing. Everything works fine when the user
    enters data - save/open, display, etc.
    Where I am running into a problem is when the NSManagedObject needs to
    set some data; I simply can't get the methods to be called.

    I used Xcode to generate the Managed Object Class, which includes the
    code:

    @interface Listing (CoreDataGeneratedAccessors)
    - (void)addListItemsObject:(ListItem *)value;
    - (void)removeListItemsObject:(ListItem *)value;
    @end

    in the interface file, and I called the method in the implementation
    file:

    - (void)addListItemsObject:(ListItem *)value
    {
    NSLog(@"Here");
    }

    I have verified that the "awakeFromInsert:" method is called on that
    class, and the code compiles fine, but I never see "Here" in the
    console and when I put a breakpoint on the NSLog() line, it is never
    hit.

    In the code listings in the NSPersistentDocumentTutorial, it appears
    that this should work fine... what am I doing wrong?

    I appreciate any help.

    TIA,
    Steven
  • You've detailed the code part, but you didn't tell us what you did to
    test it. So we still do not know what actually failed. It may well be
    that your expectations are wrong. In fact, that seems to be the case
    from your explanation. You say that you have problems when the
    "NSManagedObject needs to set some data". That usually means changing
    a property. Than you go on describing methods to modify a
    relationship. So what are you actually modifying?

    Christiaan

    On 9 Jan 2008, at 2:05 PM, Steven Hatfield wrote:

    > Hi All,
    >
    > I am a newbie ObjC/Cocoa programmer, and I have a small core data
    > application that I am writing. Everything works fine when the user
    > enters data - save/open, display, etc.
    > Where I am running into a problem is when the NSManagedObject needs
    > to set some data; I simply can't get the methods to be called.
    >
    > I used Xcode to generate the Managed Object Class, which includes
    > the code:
    >
    > @interface Listing (CoreDataGeneratedAccessors)
    > - (void)addListItemsObject:(ListItem *)value;
    > - (void)removeListItemsObject:(ListItem *)value;
    > @end
    >
    > in the interface file, and I called the method in the
    > implementation file:
    >
    > - (void)addListItemsObject:(ListItem *)value
    > {
    > NSLog(@"Here");
    > }
    >
    >
    > I have verified that the "awakeFromInsert:" method is called on
    > that class, and the code compiles fine, but I never see "Here" in
    > the console and when I put a breakpoint on the NSLog() line, it is
    > never hit.
    >
    > In the code listings in the NSPersistentDocumentTutorial, it
    > appears that this should work fine... what am I doing wrong?
    >
    > I appreciate any help.
    >
    > TIA,
    > Steven
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • Christiaan,

    Thanks for your quick reply. You are absolutely correct, that's what I
    get for posting before my morning intake of caffeine... ;-)

    To test it I am compiling in Debug mode, I placed a breakpoint on the
    NSLog() line and pressed "Debug". I brought up the console and the
    NSLog() call never fires, and the breakpoint is never hit, even though
    I can see in the GUI that the object is being used. The
    awakeFromInsert: *is* being called, I see NSLog() output in the
    console from that method.

    My intention is to get the ListItem object that is being inserted into
    the "Listing" object's ListItems (collection? What would it be called?
    Like I said... I'm a newbie...), and modify one of its properties,
    "itemNumber" to contain the count of the # of listItems that are in
    the Listing to which it belongs.  I thought it best to do this from
    the Listing object itself, since from the wording of the method it
    receives some hint that a new listItem is being inserted into it.

    It's really just a simple app to get familiar with Core Data, after
    working through Hillegass' awesome intro to Mac OS X Programming book.
    He doesn't cover Core Data, so it's very new to me...

    There are likely other, better ways to do this, but hopefully with
    your help, I can figure it out.

    Thanks,
    Steven

    On Jan 9, 2008, at 8:16 AM, Christiaan Hofman wrote:

    > You've detailed the code part, but you didn't tell us what you did
    > to test it. So we still do not know what actually failed. It may
    > well be that your expectations are wrong. In fact, that seems to be
    > the case from your explanation. You say that you have problems when
    > the "NSManagedObject needs to set some data". That usually means
    > changing a property. Than you go on describing methods to modify a
    > relationship. So what are you actually modifying?
    >
    > Christiaan
    >
    > On 9 Jan 2008, at 2:05 PM, Steven Hatfield wrote:
    >
    >> Hi All,
    >>
    >> I am a newbie ObjC/Cocoa programmer, and I have a small core data
    >> application that I am writing. Everything works fine when the user
    >> enters data - save/open, display, etc.
    >> Where I am running into a problem is when the NSManagedObject needs
    >> to set some data; I simply can't get the methods to be called.
    >>
    >> I used Xcode to generate the Managed Object Class, which includes
    >> the code:
    >>
    >> @interface Listing (CoreDataGeneratedAccessors)
    >> - (void)addListItemsObject:(ListItem *)value;
    >> - (void)removeListItemsObject:(ListItem *)value;
    >> @end
    >>
    >> in the interface file, and I called the method in the
    >> implementation file:
    >>
    >> - (void)addListItemsObject:(ListItem *)value
    >> {
    >> NSLog(@"Here");
    >> }
    >>
    >>
    >> I have verified that the "awakeFromInsert:" method is called on
    >> that class, and the code compiles fine, but I never see "Here" in
    >> the console and when I put a breakpoint on the NSLog() line, it is
    >> never hit.
    >>
    >> In the code listings in the NSPersistentDocumentTutorial, it
    >> appears that this should work fine... what am I doing wrong?
    >>
    >> I appreciate any help.
    >>
    >> TIA,
    >> Steven
    >> _______________________________________________
    >> MacOSX-dev mailing list
    >> <MacOSX-dev...>
    >> http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • That's all not relevant info. The question is what you're doing to
    the data model. Are you inserting an ListItem object, and how?
    Changing a property of any object is not at all relevant to the add/
    remove methods.

    Christiaan

    On 9 Jan 2008, at 3:17 PM, Steven Hatfield wrote:

    > Christiaan,
    >
    > Thanks for your quick reply. You are absolutely correct, that's
    > what I get for posting before my morning intake of caffeine... ;-)
    >
    > To test it I am compiling in Debug mode, I placed a breakpoint on
    > the NSLog() line and pressed "Debug". I brought up the console and
    > the NSLog() call never fires, and the breakpoint is never hit, even
    > though I can see in the GUI that the object is being used. The
    > awakeFromInsert: *is* being called, I see NSLog() output in the
    > console from that method.
    >
    > My intention is to get the ListItem object that is being inserted
    > into the "Listing" object's ListItems (collection? What would it be
    > called? Like I said... I'm a newbie...), and modify one of its
    > properties, "itemNumber" to contain the count of the # of listItems
    > that are in the Listing to which it belongs.  I thought it best to
    > do this from the Listing object itself, since from the wording of
    > the method it receives some hint that a new listItem is being
    > inserted into it.
    >
    > It's really just a simple app to get familiar with Core Data, after
    > working through Hillegass' awesome intro to Mac OS X Programming
    > book. He doesn't cover Core Data, so it's very new to me...
    >
    > There are likely other, better ways to do this, but hopefully with
    > your help, I can figure it out.
    >
    > Thanks,
    > Steven
    >
    > On Jan 9, 2008, at 8:16 AM, Christiaan Hofman wrote:
    >
    >> You've detailed the code part, but you didn't tell us what you did
    >> to test it. So we still do not know what actually failed. It may
    >> well be that your expectations are wrong. In fact, that seems to
    >> be the case from your explanation. You say that you have problems
    >> when the "NSManagedObject needs to set some data". That usually
    >> means changing a property. Than you go on describing methods to
    >> modify a relationship. So what are you actually modifying?
    >>
    >> Christiaan
    >>
    >> On 9 Jan 2008, at 2:05 PM, Steven Hatfield wrote:
    >>
    >>> Hi All,
    >>>
    >>> I am a newbie ObjC/Cocoa programmer, and I have a small core data
    >>> application that I am writing. Everything works fine when the
    >>> user enters data - save/open, display, etc.
    >>> Where I am running into a problem is when the NSManagedObject
    >>> needs to set some data; I simply can't get the methods to be called.
    >>>
    >>> I used Xcode to generate the Managed Object Class, which includes
    >>> the code:
    >>>
    >>> @interface Listing (CoreDataGeneratedAccessors)
    >>> - (void)addListItemsObject:(ListItem *)value;
    >>> - (void)removeListItemsObject:(ListItem *)value;
    >>> @end
    >>>
    >>> in the interface file, and I called the method in the
    >>> implementation file:
    >>>
    >>> - (void)addListItemsObject:(ListItem *)value
    >>> {
    >>> NSLog(@"Here");
    >>> }
    >>>
    >>>
    >>> I have verified that the "awakeFromInsert:" method is called on
    >>> that class, and the code compiles fine, but I never see "Here" in
    >>> the console and when I put a breakpoint on the NSLog() line, it
    >>> is never hit.
    >>>
    >>> In the code listings in the NSPersistentDocumentTutorial, it
    >>> appears that this should work fine... what am I doing wrong?
    >>>
    >>> I appreciate any help.
    >>>
    >>> TIA,
    >>> Steven
    >>> _______________________________________________
    >>> MacOSX-dev mailing list
    >>> <MacOSX-dev...>
    >>> http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >>
    >> _______________________________________________
    >> MacOSX-dev mailing list
    >> <MacOSX-dev...>
    >> http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >
  • I was thinking that when the addListItems: method is called, and the
    listItem is passed into the method, that I would be able to set the
    itemNumer property to a number other than "null" of the new object and
    let addListItems: go about its business of adding that object to the
    Listing.

    Is this not how I could do this? What would be a better way?

    Thanks,
    Steven

    On Jan 9, 2008, at 12:57 PM, Christiaan Hofman wrote:

    > That's all not relevant info. The question is what you're doing to
    > the data model. Are you inserting an ListItem object, and how?
    > Changing a property of any object is not at all relevant to the add/
    > remove methods.
    >
    > Christiaan
    >
    > On 9 Jan 2008, at 3:17 PM, Steven Hatfield wrote:
    >
    >> Christiaan,
    >>
    >> Thanks for your quick reply. You are absolutely correct, that's
    >> what I get for posting before my morning intake of caffeine... ;-)
    >>
    >> To test it I am compiling in Debug mode, I placed a breakpoint on
    >> the NSLog() line and pressed "Debug". I brought up the console and
    >> the NSLog() call never fires, and the breakpoint is never hit, even
    >> though I can see in the GUI that the object is being used. The
    >> awakeFromInsert: *is* being called, I see NSLog() output in the
    >> console from that method.
    >>
    >> My intention is to get the ListItem object that is being inserted
    >> into the "Listing" object's ListItems (collection? What would it be
    >> called? Like I said... I'm a newbie...), and modify one of its
    >> properties, "itemNumber" to contain the count of the # of listItems
    >> that are in the Listing to which it belongs.  I thought it best to
    >> do this from the Listing object itself, since from the wording of
    >> the method it receives some hint that a new listItem is being
    >> inserted into it.
    >>
    >> It's really just a simple app to get familiar with Core Data, after
    >> working through Hillegass' awesome intro to Mac OS X Programming
    >> book. He doesn't cover Core Data, so it's very new to me...
    >>
    >> There are likely other, better ways to do this, but hopefully with
    >> your help, I can figure it out.
    >>
    >> Thanks,
    >> Steven
    >>
    >> On Jan 9, 2008, at 8:16 AM, Christiaan Hofman wrote:
    >>
    >>> You've detailed the code part, but you didn't tell us what you did
    >>> to test it. So we still do not know what actually failed. It may
    >>> well be that your expectations are wrong. In fact, that seems to
    >>> be the case from your explanation. You say that you have problems
    >>> when the "NSManagedObject needs to set some data". That usually
    >>> means changing a property. Than you go on describing methods to
    >>> modify a relationship. So what are you actually modifying?
    >>>
    >>> Christiaan
    >>>
    >>> On 9 Jan 2008, at 2:05 PM, Steven Hatfield wrote:
    >>>
    >>>> Hi All,
    >>>>
    >>>> I am a newbie ObjC/Cocoa programmer, and I have a small core data
    >>>> application that I am writing. Everything works fine when the
    >>>> user enters data - save/open, display, etc.
    >>>> Where I am running into a problem is when the NSManagedObject
    >>>> needs to set some data; I simply can't get the methods to be
    >>>> called.
    >>>>
    >>>> I used Xcode to generate the Managed Object Class, which includes
    >>>> the code:
    >>>>
    >>>> @interface Listing (CoreDataGeneratedAccessors)
    >>>> - (void)addListItemsObject:(ListItem *)value;
    >>>> - (void)removeListItemsObject:(ListItem *)value;
    >>>> @end
    >>>>
    >>>> in the interface file, and I called the method in the
    >>>> implementation file:
    >>>>
    >>>> - (void)addListItemsObject:(ListItem *)value
    >>>> {
    >>>> NSLog(@"Here");
    >>>> }
    >>>>
    >>>>
    >>>> I have verified that the "awakeFromInsert:" method is called on
    >>>> that class, and the code compiles fine, but I never see "Here" in
    >>>> the console and when I put a breakpoint on the NSLog() line, it
    >>>> is never hit.
    >>>>
    >>>> In the code listings in the NSPersistentDocumentTutorial, it
    >>>> appears that this should work fine... what am I doing wrong?
    >>>>
    >>>> I appreciate any help.
    >>>>
    >>>> TIA,
    >>>> Steven
    >>>> _______________________________________________
    >>>> MacOSX-dev mailing list
    >>>> <MacOSX-dev...>
    >>>> http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >>>
    >>> _______________________________________________
    >>> MacOSX-dev mailing list
    >>> <MacOSX-dev...>
    >>> http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >>
    >
  • On Jan 9, 2008, at 5:17 PM, Steven Hatfield wrote:

    > I was thinking that when the addListItems: method is called, and the
    > listItem is passed into the method, that I would be able to set the
    > itemNumer property to a number other than "null" of the new object
    > and let addListItems: go about its business of adding that object to
    > the Listing.
    >
    > Is this not how I could do this? What would be a better way?

    It sounds like there are two separate questions here:

    1. Why is -addListItemsObject: not being called?

    2. How do you populate the itemNumber?

    It's hard to answer #1 without knowing exactly what you're doing.
    Above, you actually say -addListItems:, which is maybe a typo? In any
    case, you should describe what you're doing that you believe should
    cause -addListItemsObject: to be called.

    For question #2, yes, it's completely reasonable to set the itemNumber
    inside the -addListItemsObject:. Whether that's the best thing for
    your application is hard to say without looking at the entire
    application.

          - Scott
previous month january 2008 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