我有一个带有url字符串属性和标题的历史对象.我想使用包含搜索字符串的url搜索所有对象的历史记录,然后删除所有重复项.
示例:我有一系列历史记录对象,其中20个都是" https://www.google.com ",其中4个是" https://www.google.com/#q=search ",我想获得一个数组后面只有一个对象,其网址值为" https://www.google.com ",网址值为" https://www.google.com/#q=search "
这是我当前的代码,它搜索历史记录并返回与字符串匹配的所有对象:
- (NSArray *)historyObjectsContainingQuery:(NSString *)query {
NSMutableArray *matchingObjects = [[NSMutableArray alloc] init];
HistoryManager *HM = [HistoryManager sharedInstance];
for (int i=0; i<[[HM history] count]; i++) {
//History "days"
HistoryObject *historyItem = HistoryObject([[HistoryManager sharedInstance] history][i]);
for (int o=0; o<[historyItem.objects count]; o++) {
//Each object inn each history day
HistoryObject *HO = HistoryObject(historyItem.objects[o]);
if ([HO.title rangeOfString:query options:NSCaseInsensitiveSearch].location != NSNotFound) {
//history objects with their title containing the query string
[matchingObjects addObject:HO];
}
} …Run Code Online (Sandbox Code Playgroud)