views:

713

answers:

1

hi experts, i'm scanning wifi info using NSMutableArray, but there are few duplicate values appear, so i try to use following code but still getting the duplicate values,

if([scan_networks count] > 0) 
{
 NSArray *uniqueNetwork = [[NSMutableArray alloc] initWithArray:[[NSSet setWithArray:scan_networks] allObjects]];
 [scan_networks removeAllObjects];

 NSSortDescriptor *networkName = [[[NSSortDescriptor alloc] initWithKey:@"SSID_STR" ascending:YES] autorelease];
 NSArray *descriptors = [NSArray arrayWithObjects:networkName,nil];

 [scan_networks addObjectsFromArray:[uniqueNetwork sortedArrayUsingDescriptors:descriptors]];
}

how this can be resolve, thanks

+2  A: 

You should be using an NSMutableSet in the first place.

For eliminating all double entries in an array, see this question:
Make NSMutableArray or NSMutableSet unique.

Georg
i have try with NSMutableSet, but still can't remove,
Apache
`NSSet` requires that your objects implement `-hash` and `-isEqual:`, have you done this?
Georg