0

我有一个获取请求如下:

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
4

1 回答 1

1

是的。这在我看来是正确的。

这是我对另一个问题的回答,它包含简单的说明和代码,可以让准系统核心数据项目启动并运行我经常使用这个基本设置来快速测试这样的事情。

于 2012-10-18T09:00:25.863 回答