Forum Navigation
You need to log in to create posts and topics.

Removing an NSDictionary from an NSMutableArray

Posted by: fbcocoa.bw <fbcocoa.bw@...>

Brian wrote:


Hi Guys( I’m squeezing in some programming time this morning while things are quiet ),
My efforts to accomplish the subject in some elegant fashion have so far failed. The basic scenario is I capture a row from a table view and use the data in that row to create a dictionary ( and the keys used to make it are the same keys used in the dictionaries of the target array ----i.e. the array where a deletion is desired ). When I display the contents of 'dict' and ’testItem' in the debugger, the keys and values are identical(AFAICT). I don’t want to resort to writing a large predicate and doing the search that way since what I’m doing seems simple. Once I locate the index of the dict within the CFMutableArray, I want to remove it. I’ve tried other methods like 'removeObject:' but they also fail. I’m probably overlooking something obvious. Thanks for any ideas. Brian S.
        // get the row data from the tableview
        NSMutableDictionary *tblViewItem = [vehicleMaintArray objectAtIndex:row];
        
        // create a dict using keys for gVehicleHistoryArrayRef ( a CFMutableArrayRef so has to be cast )
        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                              [tblViewItem objectForKey:ColVehicleIdentifier],kMakeModelNameKey,        // string
                              [tblViewItem objectForKey:ColProviderIdentifier],kProviderNameKey,        // string
                              [tblViewItem objectForKey:ColTaskIdentifier],kServiceTaskNameKey,         // string
                              [tblViewItem objectForKey:ColMileageIdentifier],kServiceMileageKey,          // CF/NSNumber
                              [tblViewItem objectForKey:ColDateIdentifier],kServiceDateKey,      // CF/NSDate
                              [tblViewItem objectForKey:ColCostIdentifier],kServiceCostKey,      // string
                              nil];
       
        // search for dict in gVehicleHistoryArrayRef( an array of dicts )
        
        for ( NSDictionary *testItem in (NSMutableArray *)gVehicleHistoryArrayRef )
        {
            if ( [testItem isEqualToDictionary:dict] )
                  {
                     NSLog(@"found it %ld", foundIdx); 
                  }
            foundIdx++;
        }

Have you tried  removeObjectAtIndex: ?


To unsubscribe, e-mail: fbcocoa-unsubscribe@welovegod.org For additional commands, e-mail: fbcocoa-help@freegroups.net