简体   繁体   中英

Filtering NSMutable Array of custom objects

I have a NSMutableArray containing custom objects of type Episode. Each of these objects has multiple NSStrings as properties. Now I would like to filter the array to check if I have this episode (parsed from an XML) already and update it or create a new Episode object.

I use the following code:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"weblink = %@", currentEpisode.weblink];

NSArray* hits = [appDelegate.episodesList filteredArrayUsingPredicate:predicate];

currentEpisode is the episode I parsed from the XML and I want to check for, episodeList is my NSMutableArray with Episode objects. weblink is one of the NSString properties containing an URL.

When I check on weblink everything works fine. BUT URLs in Podcastfeeds can change so I want to check on an other property called kuhid which is a unique identifier provided in the feed. 'kuhid' is also an NSString (example: 644ED540-EDCA-4D4F-882E-4B3106DDAAB3). When I check on 'kuhid' the predicate never matches and I get duplicates. Both properties are NSStrings, both correctly synthesized. Same if I try one of my other NSString (eg title) propierties.

Have anybody an idea why that work only with weblink and not with any of my other properties?

Are you sure your string exactly matches, namely you don't have leading or trailing spaces, or lowercase vs. uppercase, or different dashes used (long dash vs. short dash for example) or invisible characters?

Try to log the NSData representation of both strings to compare them byte by byte in the debugger just to be sure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM