• 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: mutableArrayValueForKeyPath gives me valueForUndefinedKey
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mutableArrayValueForKeyPath gives me valueForUndefinedKey


  • Subject: Re: mutableArrayValueForKeyPath gives me valueForUndefinedKey
  • From: Michael Hanna <email@hidden>
  • Date: Sat, 9 Jul 2005 09:32:36 -0400

OK fair enough but then why is it that when this line of code:

NSMutableArray * entriesArray = [self mutableArrayValueForKey: @"entries"];

gives me a notifying array:

(gdb) po entriesArray
<NSKeyValueNotifyingMutableArray 0x3a8ff0>(
<NSKVONotifying_DLEntry: 0x380840>
)

this line of code:

    NSMutableArray *anEntryPassagesArray = [anEntry passages];

does not:

(gdb) po anEntryPassagesArray
<NSCFArray 0x3bf6a0>(
<NSKVONotifying_DLPassage: 0x3e08d0>
)

a DLPassage added to this array does not get observed in the tableview

but in another method I do something similar, the anEntryPassagesArray = [anEntry passages]; gives me an NSCFArray but in that methed the new passage gets observed and added to the tableview(notice the NSKVONotifying_DLPassage object already there).

here is the non-observing code in its entirety

if ([oEntriesTable selectedRow] == -1)
return;
NSString *passageString = [NSString stringWithString: [[[oPassageTextView textStorage] string] copy]];
NSMutableArray * entriesArray = [self mutableArrayValueForKey: @"entries"];
DLEntry *anEntry = [entriesArray objectAtIndex:[oEntriesTable selectedRow]];
NSMutableArray *anEntryPassagesArray = [anEntry passages];
DLPassage *aPassage = [[DLPassage alloc] init];
NSArray * passageKeys = [NSArray arrayWithObjects: @"dateCreated", @"body", nil];
NSArray * passageValues = [NSArray arrayWithObjects: [NSDate date], passageString, nil];
NSMutableDictionary *passageDict = [NSMutableDictionary dictionaryWithObjects: passageValues forKeys: passageKeys];
[aPassage setProperties:passageDict];
[anEntryPassagesArray addObject:aPassage];
[aPassage release];


conversely here is the code that adds a DLEntry and DLPassage at the same(and observes fine):

NSString *passageString = [NSString stringWithString: [[[oPassageTextView textStorage] string] copy]];
NSMutableArray * entriesArray = [self mutableArrayValueForKey: @"entries"];
DLEntry *anEntry = [[DLEntry alloc] init];
DLPassage *aPassage = [[DLPassage alloc] init];
NSMutableArray *anEntryPassagesArray = [anEntry passages];
NSArray * entryKeys = [NSArray arrayWithObjects: @"title", @"dateCreated", @"dateModified", nil];
NSArray * entryValues = [NSArray arrayWithObjects: [oEntryTitle stringValue], [NSDate date], [NSDate date], nil];
NSArray * passageKeys = [NSArray arrayWithObjects: @"dateCreated", @"body", nil];
NSArray * passageValues = [NSArray arrayWithObjects: [NSDate date], passageString, nil];
NSMutableDictionary *entryDict = [NSMutableDictionary dictionaryWithObjects: entryValues forKeys: entryKeys];
NSMutableDictionary *passageDict = [NSMutableDictionary dictionaryWithObjects: passageValues forKeys: passageKeys];
[anEntry setProperties:entryDict];
[aPassage setProperties:passageDict];
[anEntryPassagesArray addObject:aPassage];
[aPassage release];
[entriesArray addObject:anEntry];
[anEntry release];



confused, Michael

On 8-Jul-05, at 7:26 PM, Charilaos Skiadas wrote:

Of course this would give you an error, since anEntry is not a key in your class. What you possibly want in place of:
passagesArray = [self mutableArrayValueForKeyPath: @"anEntry.passages"];

is:
passagesArray = [anEntry mutableArrayValueForKeyPath: @"passages"];


Or some such. Point is, you should not be using anEntry in the keyPath.

looked into this by searching the archives but came up with nothing on mutableArrayValueForKeyPath. Any ideas why this is happening? I'm quite the newb on all things bindings.

In that case, you will want to start by reading on key-value coding
http://developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueCoding/index.html
and possibly key-value observing
http://developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueObserving/index.html


After that, it should make more sense why you should not expect your code as it was to work.
regards,
Michael


Haris



_______________________________________________ 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: mutableArrayValueForKeyPath gives me valueForUndefinedKey
      • From: Charilaos Skiadas <email@hidden>
References: 
 >mutableArrayValueForKeyPath gives me valueForUndefinedKey (From: Michael Hanna <email@hidden>)
 >Re: mutableArrayValueForKeyPath gives me valueForUndefinedKey (From: Charilaos Skiadas <email@hidden>)

  • Prev by Date: addobserver forkeypath breaks NSMetadataQuery live updates?
  • Next by Date: Re: Documentation frustrations
  • Previous by thread: Re: mutableArrayValueForKeyPath gives me valueForUndefinedKey
  • Next by thread: Re: mutableArrayValueForKeyPath gives me valueForUndefinedKey
  • Index(es):
    • Date
    • Thread