我有一个非常简单的NSPredicate
,它应该过滤我的自定义对象数组。为什么这个简单的NSPredicate过滤我的数组
NSLog(@"%@", self.displayedSources);
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@", searchText];
[self.displayedSources filterUsingPredicate:predicate];
NSLog(@"%@", self.displayedSources);
然而,这给我留下了0的结果(即使空searchText
)。
我知道数组中填充自定义类型,其中报头看起来像这样
@interface NewsSourceObject : NSObject <NSCoding>
@property (nonatomic, copy, readonly) NSString *objectId;
@property (nonatomic, copy, readonly) NSString *name;
...
@end
我知道正在执行的代码,因为我已经添加打印语句记录的长度的26个目的数组应用谓词(26 - 0)之前和之后的数组。
我一直用这个拉我的头发半天以上,因为我不知道什么是错的。
EDIT 1: 我尝试之前以及将所述谓词后记录所述数组的内容使用的对象此description
方法(参见顶部代码块):
- (NSString *)description {
return [NSString stringWithFormat:@"%@", self.name];
}
而这正是我得到:
2015-06-08 02:57:28.521 Newsloop[8554:1578121] (
"ABC News",
"BBC News",
"Bleacher Report",
"Business Insider",
"BuzzFeed News",
CNN,
"Daily Mail Online",
...
)
2015-06-08 02:57:28.522 Newsloop[8554:1578121] (
)
是名称字段实际上填入你的对象? –
是的,我尝试打印数组和所有名称字段包含文本 – Aleksander
无关,但为什么属性声明“复制”不“保留”? –