valueForUndefinedKey confusion
Hello All, I have an NSMutableDictionary I'm trying to read from, but it's giving me valueForUndefinedKey errors. I can NSLog the key successfully, so I'm very confused as to what's going on. NSLog(@Total number of components in work: %i, [AllComponents count]); for(NSString* cKey in AllComponents) { NSLog(@key? %@, cKey); MnSComponent *comp = (MnSComponent*)[AllComponents valueForKey:cKey]; [comp buildPitchMatrix]; [comp calculateTension]; } The NSLog prints the expected key, then the code gags on the next line. ??? - James B Maxwell Composer/Doctoral Student School for the Contemporary Arts (SCA) School for Interactive Arts + Technology (SIAT) Simon Fraser University jbmaxw...@rubato-music.com jbmax...@sfu.ca ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: valueForUndefinedKey confusion
On 16/02/2010, at 8:56 AM, James Maxwell wrote: I have an NSMutableDictionary I'm trying to read from, but it's giving me valueForUndefinedKey errors. I can NSLog the key successfully, so I'm very confused as to what's going on. NSLog(@Total number of components in work: %i, [AllComponents count]); for(NSString* cKey in AllComponents) { NSLog(@key? %@, cKey); MnSComponent *comp = (MnSComponent*)[AllComponents valueForKey:cKey]; [comp buildPitchMatrix]; [comp calculateTension]; } The NSLog prints the expected key, then the code gags on the next line. ??? Try -objectForKey: instead of -valueForKey: there might be some subtlety of use KVC versus direct access that's screwing things up here. The key might contain characters that can be misinterpreted by KVC - containing '@' or '.' characters for example. Also, are you certain that buildPitchMatrix and calculateTension are not mutating the dictionary? If they do the iteration will fail. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: valueForUndefinedKey confusion
Ha - that did it! As expected, you are a rock star, Graham. (and no, the following methods don't muck with the dictionary - it's obviously some subtlety in KVC... There is an underscore in the key string, so that probably borked it.) cheers, J. On 2010-02-15, at 2:09 PM, Graham Cox wrote: On 16/02/2010, at 8:56 AM, James Maxwell wrote: I have an NSMutableDictionary I'm trying to read from, but it's giving me valueForUndefinedKey errors. I can NSLog the key successfully, so I'm very confused as to what's going on. NSLog(@Total number of components in work: %i, [AllComponents count]); for(NSString* cKey in AllComponents) { NSLog(@key? %@, cKey); MnSComponent *comp = (MnSComponent*)[AllComponents valueForKey:cKey]; [comp buildPitchMatrix]; [comp calculateTension]; } The NSLog prints the expected key, then the code gags on the next line. ??? Try -objectForKey: instead of -valueForKey: there might be some subtlety of use KVC versus direct access that's screwing things up here. The key might contain characters that can be misinterpreted by KVC - containing '@' or '.' characters for example. Also, are you certain that buildPitchMatrix and calculateTension are not mutating the dictionary? If they do the iteration will fail. --Graham James B Maxwell Composer/Doctoral Student School for the Contemporary Arts (SCA) School for Interactive Arts + Technology (SIAT) Simon Fraser University jbmaxw...@rubato-music.com jbmax...@sfu.ca ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com