Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Way of removing by value from CFMutableArray



On Fri, 30 Sep 2005 10:22:24, George Warner <email@hidden> wrote:

> On Fri, 30 Sep 2005 16:12:06 +0530, "Ayyapu Reddy Pallam"
> <email@hidden> wrote:
>> I have list of indices of values of CFMutableArray. If i try to remove the
>> values from the array looping throgh the indices array using
>> CFArrayRemoveValueAtIndex() indices may not be valid after the first
>> removal(it
>> decrements indices). So do we have some function like CFArrayRemoveObject()
>> or
>> CFArrayRemoveValue() where  i can pass the value to be removed from the
>> CFArray.
>> Or any other way of removing by value from CFMutableArray.
> 
> If you loop backwards then you won't be trying to remove the wrong indices:
> 
> CFIndex idx;
> for (idx = CFArrayGetCount(tCFMutableArrayRef); idx > 0; idx--) {
> CFStringRef myValue = (CFStringRef)
> CFArrayGetValueAtIndex(tCFMutableArrayRef, idx);
> if (kCFCompareEqualTo ==
> CFStringCompare(myValue, CFSTR("FooBar"), 0))
> {
> CFArrayRemoveValueAtIndex(tCFMutableArrayRef, idx);
> }
> }

Index for CFArray APIs is 0 based.

Or just adjust index appropriately when deleting:

index = 0;
while (index != count) {
  val = CFArrayGetValueAtIndex(index);
  if (val == need to be deleted) CFArrayRemoveValueAtIndex(index);
  else index++;
}

Mike

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.