我有一个获取请求如下:
NSFetchRequest *songRequest = [NSFetchRequest fetchRequestWithEntityName:@"Song"];
我还有一个名为genreFilter 的类型的NSSet (NSManagedObjects)。
我想设置一个谓词来过滤与genreFilter中的流派有关系的歌曲。
我可以以这种方式设置 NSPredicate 吗:
NSPredicate *songRequestPredicate = [NSPredicate predicateWithFormat:@"genre IN %@", [_genreFilter allObjects]];
?
流派如下所示:
@interface Genre : NSManagedObject
@property (nonatomic, strong) NSNumber * id;
@property (nonatomic, strong) NSString * name;
@property (nonatomic, strong) NSSet *preset;
@property (nonatomic, strong) NSSet *song;
@end
@interface Genre (CoreDataGeneratedAccessors)
- (void)addPresetObject:(Preset *)value;
- (void)removePresetObject:(Preset *)value;
- (void)addPreset:(NSSet *)values;
- (void)removePreset:(NSSet *)values;
- (void)addSongObject:(Song *)value;
- (void)removeSongObject:(Song *)value;
- (void)addSong:(NSSet *)values;
- (void)removeSong:(NSSet *)values;
@end
和这样的歌曲:
@interface Song : NSManagedObject
@property (nonatomic, strong) NSNumber * arousal;
@property (nonatomic, strong) NSNumber * id;
@property (nonatomic, strong) NSNumber * match;
@property (nonatomic, strong) NSNumber * popularity;
@property (nonatomic, strong) NSNumber * valence;
@property (nonatomic, strong) NSNumber * cloud;
@property (nonatomic, strong) Genre *genre;
@property (nonatomic, strong) Year *year;
@property (nonatomic, strong) Period *period;
@property (nonatomic, strong) NSNumber *yearReleased;
@property (nonatomic, assign) float score;
@property (nonatomic, readonly) MPMediaItem *mediaItem;
@end