Does NSArray have the capability of matching a string in an array with the closest representation of that string in another array?
For example:
NSString *search = @"apple p";
NSArray *array = [[NSArray alloc]initWithObjects:@"apple",@"apple pie",@"apple pies", @"apple juice", nil];
//Now we want to look for a similar string
[array ?];
The desired result should be: apple pie (most similar string). Any ideas how this could be done?
You could sort the array based on similarity, then retrieve the last element in the sorted array: the most similar string. Assuming you’ve defined some method
similarityTo:in a category onNSString, something like the following should do the trick: