• 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
Does willChange:valuesAtIndexes:forKey: work correctly?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Does willChange:valuesAtIndexes:forKey: work correctly?


  • Subject: Does willChange:valuesAtIndexes:forKey: work correctly?
  • From: Steve Weller <email@hidden>
  • Date: Thu, 15 Mar 2007 22:00:28 -0700


I have a section of code that scans a dictionary that is acting as a cache for dictionaries that contain images and text. I ahve the cache for performance reasons: getting the images is costly. For each entry it tells the NSArrayController that it has changed the value of a specific index with willChange:valuesAtIndexes:forKey: and didChange:valuesAtIndexes:forKey:.


So I expect the array controller to then request data only for that one index. But instead it asks for *all* of the values in the array starting at zero. This defeats the purpose of having the cache. Am I understanding this correctly? I'm not calling willChange anything else anywhere else. It is as though my NSIndexSet is incorrect.

I have the array controller bound to my class and have methods objectInImageTableDataAtIndex: and countOfImageTableData: so I can provide the data it needs. This all works. The controller happily fills my table.

The keys into my cache are NSStrings of the index converted to a string.

// Replaces random string in all cached image data dictionaries
- (void)displayExampleString;
{
NSIndexSet *index;
unsigned keyInt;
NSString *key;
NSMutableDictionary *cacheEntry;
NSEnumerator *e = [_imageDataCache keyEnumerator];
while(nil!=(key=[e nextObject])) {
// Replace the text for this image with new text
keyInt = [key intValue];
index = [NSIndexSet indexSetWithIndex:keyInt];
[self willChange:NSKeyValueChangeReplacement valuesAtIndexes:index forKey:@"imageTableData"];
cacheEntry = [_imageDataCache objectForKey:key];
[cacheEntry setObject:[self textForImageAtIndex:(unsigned)keyInt] forKey:@"text"];
[self didChange:NSKeyValueChangeReplacement valuesAtIndexes:index forKey:@"imageTableData"];
}
}


textForImageAtIndex: returns the new string I need to put into the cached data and so to a column on the table.

And this is the stack. #7 calls the method above and #1 is the call back from the array controller. The index at #7 is 2, but at #1 it is called for the values 0 and up to the size of the array. I am suspicious of #5: refresh detail content in background?

#0 0x1bc3e36e in -[Random_Wok textForImageAtIndex:] at Random_Wok.m:813
#1 0x1bc3f387 in -[Random_Wok objectInImageTableDataAtIndex:] at Random_Wok.m:1090
#2 0x935259ad in -[NSArrayController _modifySelectedObjects:useExistingIndexesAsStartingPoint:avoidsEmptySele ction:addOrRemove:sendObserverNotifications:forceUpdate:]
#3 0x93523800 in -[NSArrayController _arrangeObjectsWithSelectedObjects:avoidsEmptySelection:operationsMask:u seBasis:]
#4 0x935233ef in -[NSArrayController setContent:]
#5 0x93522cc0 in -[NSArrayDetailBinder _refreshDetailContentInBackground:]
#6 0x926c6704 in -[NSObject(NSKeyValueObserverNotification) didChange:valuesAtIndexes:forKey:]
#7 0x1bc3e2c2 in -[Random_Wok displayExampleString] at Random_Wok.m:791
#8 0x1bc3b6a2 in -[Random_Wok willBeActivated] at Random_Wok.m:169
#9 0x00391366 in ??
#10 0x0005c984 in ??
#11 0x9336bd88 in -[NSApplication sendAction:to:from:]
#12 0x95e5ce5d in NSProCenterRect
#13 0x0001017d in ??


--
Bagelturf Blog  http://homepage.mac.com/bagelturf/



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Does willChange:valuesAtIndexes:forKey: work correctly?
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: Re: True object size
  • Next by Date: Re: slide nsimage
  • Previous by thread: Re: True object size
  • Next by thread: Re: Does willChange:valuesAtIndexes:forKey: work correctly?
  • Index(es):
    • Date
    • Thread