Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove all objects with the same property value but one in NSMutableArray
    primarykey
    data
    text
    <p>I have a history object with a url string property and title. I want to search all the history for objects with the url containing a search string, then remove all duplicates. </p> <p>Example: I have an array of history objects and 20 of them are all "<a href="https://www.google.com" rel="nofollow">https://www.google.com</a>" and 4 are "<a href="https://www.google.com/#q=search" rel="nofollow">https://www.google.com/#q=search</a>", I want to get an array back with only one object with the url value of "<a href="https://www.google.com" rel="nofollow">https://www.google.com</a>" and one url value of "<a href="https://www.google.com/#q=search" rel="nofollow">https://www.google.com/#q=search</a>"</p> <p>Here is my current code that searches the history and returns all objects matching the string:</p> <pre><code> - (NSArray *)historyObjectsContainingQuery:(NSString *)query { NSMutableArray *matchingObjects = [[NSMutableArray alloc] init]; HistoryManager *HM = [HistoryManager sharedInstance]; for (int i=0; i&lt;[[HM history] count]; i++) { //History "days" HistoryObject *historyItem = HistoryObject([[HistoryManager sharedInstance] history][i]); for (int o=0; o&lt;[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]; } } } return matchingObjects; } </code></pre> <p>Then i log each url value:</p> <p>self.foundInBookmarksAndHistory = [self historyObjectsContainingQuery:textField.text]; for (HistoryObject *HO in self.foundInBookmarksAndHistory) { NSLog(@"%@",HO.url); }</p> <p>and here is the results:</p> <pre><code>https://www.google.com/ 2013-09-15 13:48:49.382 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.384 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.385 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.387 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.388 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.390 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.391 Flow HD[3599:60b] https://www.google.com/search?q=yahoo 2013-09-15 13:48:49.392 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.394 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.395 Flow HD[3599:60b] https://www.google.com/search?q=Sup 2013-09-15 13:48:49.397 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.398 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.400 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.402 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.404 Flow HD[3599:60b] https://www.google.com/ 2013-09-15 13:48:49.405 Flow HD[3599:60b] https://www.google.com/ </code></pre> <p>There is A LOT more, how can i remove each object with that same value? the objects are not equal, but do have equal urls.</p> <p>I've tried NSPredicate and using more for loops to go through and find matching objects but im always left with 2 or more of the same objects with the same property.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload