• 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
Object from valueForKey is invalid
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Object from valueForKey is invalid


  • Subject: Object from valueForKey is invalid
  • From: Theo Vosse <email@hidden>
  • Date: Wed, 21 Sep 2005 13:17:19 +0200

Hi,

I've created a slightly strange mixture of my own document structure and an NSPersistentDocument with a controller, an unholy marriage, some might say. The details are as follows:

- The main document window contains all sorts of parameters (in two tabs) and a set of sentences with associated information in a third tab.
- The first two tabs are bound directly to the members of a class via (Cocoa) bindings.
- The third tab contains a table view with a single column. This value of this column is bound to an array controller (named "Sentence Array Controller"), which gets its managedObjectContext (via a binding) from an object called "Sentences". This is a sub-class of NSPersistentDocument. It currently has two members: text and comment.
- The "Sentences" object is supposed to contain members of class "Sentence", which is a data model. The class Sentence itself is declared and derives from NSManagedObject.
- All these objects are instantiated from the nib file, and the main structure contains outlets to the table view, the array controller and the Sentences object.


The reason for this set-up is that everything but the interface should be platform independent. Consequently, the (xml) file containing all the settings must be readable and writable through a C+ + module and the data contained must be accessible from other C++ modules.

Reading the document works fine. After the nib has been loaded, I check the list of sentences, add a new Sentence object for each of them, and fill in the data, like this:

NSManagedObject *newSentence = [sentences newSentence];
[newSentence setValue:[NSString stringWithCString:sentSpec- >sentence]
forKey:@"text"];
[newSentence setValue:[NSString stringWithCString:sentSpec- >comment]
forKey:@"comment"];


This works like a charm. The sentences show up, and when one is selected, the associated comment shows up in a field (in a separate drawer window).

The problem is that I cannot obtain the text from inside the program. E.g., this code

NSArray* selectedSentences = [[sentenceArrayController selectedObjects] retain];
for (unsigned int index = 0; index != [selectedSentences count]; index++)
{
Sentence* sentence = (Sentence*) [[selectedSentences objectAtIndex:index] retain];
NSString* text = [[sentence valueForKey:@"text"] retain];
// ...
}


doesn't work. The number of selected sentences seems to be correct, but the object that ends up in the variable "text" is invalid (i.e., it is an NSCFString object, whose description is "Invalid"). I have tried with and without

        [sentence willAccessValueForKey:@"text"];
        ...
        [sentence didAccessValueForKey:@"text"];

around it, but that doesn't help, nor does changing "Sentence" into NSManagedObject, nor using "selection" instead of selectedObjects.

Does anybody have a clue to what's going on? Perhaps a strange thing that I see (each time I open the document, the sentences appear in another order) is related to this problem?

Thanks,

    Theo

_______________________________________________
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


  • Prev by Date: Re: Newbie Q about NSCoder
  • Next by Date: Re: Display RTF & RTFD file in NSTextView
  • Previous by thread: Re: Newbie Q about NSCoder
  • Next by thread: Re: Object from valueForKey is invalid
  • Index(es):
    • Date
    • Thread