ios - Comparing two arrays with NSPredicate -
i've 2 array, 1 represents list of full-size images , other 1 represents images' thumbnail. there way, using nspredicate, check if full-size image has thumbnail?
the thumb called img{number}_thumb.jpg , full-size image called img{number}.jpg.
using arrays, strings , loop :
nsarray *thumbs=@[@"img1_thumb.jpg",@"img2_thumb.jpg",@"img3_thumb.jpg",@"img4_thumb.jpg",@"img5_thumb.jpg",]; nsarray *images=@[@"img1",@"img2",@"img3",@"img41",@"img5"]; bool issame=yes; (nsstring *name in images) { if (![thumbs containsobject:[nsstring stringwithformat:@"%@_thumb.jpg",name]]) { issame=no; nslog(@"%@ doesn't has thumb image",name); break; //if first not found not enough remove break } } nslog(@"%@",issame?@"all thumb has image":@"all thumb not have image");
using nspredicate:
for (nsstring *image in images) { nspredicate *predicate=[nspredicate predicatewithformat:@"self [c]%@",[nsstring stringwithformat:@"%@_thumb.jpg",image]]; nsarray *filtered=[thumbs filteredarrayusingpredicate:predicate]; if (filtered.count==0) { nslog(@"%@ not found",image); } }
Comments
Post a Comment