ios - retain only unique values in array -
this question exact duplicate of:
i have array of strings. need retain unique values, ie. want remove repititions. eg: if array {string1, string1, string1, string2, string3, string3} final array should {string1, string2, string3}
for(int p = 0; p < [allnewsdates count]; p++) { nslog(@"%@",allnewsdates[p]); for(int q = p+1; q < [allnewsdates count]; q++) { nslog(@"%@ %@",allnewsdates[p],allnewsdates[q]); if([allnewsdates[p] isequaltostring:allnewsdates[q]]) { flag = yes; t = q; break; } } if(flag) { //[self.date addobject:alldates[p]]; [allnewsdates removeobjectatindex:p]; nslog(@"%i",[allnewsdates count]); } nslog(@"%i",p); flag = no; } i'm following above procedure extract unique dates array of dates. works ok. problem this: have news view controller shows news feed. if user selects news there, gets added favorites. if select news items in 1 go, favorites table shows news according date(different dates appear once 9th , 10th of may), if add news, go favorites, go news , click on news item(say 10th of may) , access favorites again, i'm getting 10th may twice. going wrong? please help!!
you can use kvc collection operators:
nsarray* uniquedates = [allnewdates valueforkeypath:@"@distinctunionofobjects.self"] more details here: http://www.nshipster.com/kvc-collection-operators
Comments
Post a Comment