简体   繁体   中英

NSPredicate with core data objects

I have an array which consist of core data class objects. I want to use NSPredicate (for suggestive search) to filter out a particular property of that class.

Requirement I am having a core data classes: AlbumDetails (properties- album name, albumType,etc) i want to access AlbumDetails.AlbumName property using NSPredicate for my search bar text. I currently know using predicate for simple array or dictionary structures, but how can i use predicate for a property of a particular class.

You can use something like

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"albumName contains[cd] %@", searchString];

Where albumName is the property of your class. contains will help you to get all the albums whose name contains the searchString

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