我正在尝试替换数组中的文本,并且由于某种原因代码不起作用,尽管Xcode没有行警告,但它会导致崩溃。
即。 “名字,2013”
剥离“,2013”
导致
“名称”
我做错了什么,对于我的生活,我无法解决这个问题并迫切需要帮助?
有问题的具体行是“案例ITSectionTypeAuthor:”
- (void)setUpDataByType:(ITSectionType) type andFilter:(NSString *)filter {
self.type = type;
self.filter = (filter)? filter : @"";
[self.sections removeAllObjects];
NSPredicate *predicate = nil;
NSString *descriptorKey = @"genus";
NSArray *rowData = [[ITData sharedObject] animals]; //coming form singleton
//generate predicate
switch (self.type) {
case ITSectionTypeAuthor:
predicate = [NSPredicate predicateWithFormat:@"describer componentsSeparatedByString:@", "] objectAtIndex:0] LIKE %@", filter];
break;
default:
predicate = nil;
break;
}
答案 0 :(得分:1)
我认为问题出在这一行:
predicate = [NSPredicate predicateWithFormat:@"describer componentsSeparatedByString:@", "] objectAtIndex:0] LIKE %@", filter];
您正在创建一个objective-c字符串:
@"describer componentsSeparatedByString:@"
然后是C字符串:
"] objectAtIndex:0] LIKE %@"
那不可能是对的,可以吗?我想你想要:
predicate = [NSPredicate predicateWithFormat:@"describer LIKE %@", [[filter componentsSeparatedByString:@", "] objectAtIndex:0]];