作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,我有一个字典数组,我想从中查找酒店名称,但不断收到此错误
[<__NSCFDictionary 0x7fdf8a926250> valueForUndefinedKey:]: this class is not key value coding-compliant for the key HName.
searchHotelNameString = _txtHotelSearch.text;
_resultObjectsArray = [NSArray array];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"@HName like %@",
searchHotelNameString];
_resultObjectsArray = [self.arrHotelResults filteredArrayUsingPredicate:predicate];
{
"@HIndex" = 5;
"@HName" = "XYZ Plaza Hotel Dubai";
"@Lattitude" = "25.2174";
}
最佳答案
尝试以下格式字符串:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF['@HName'] CONTAINS %@",
searchHotelNameString];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF['@HName'] LIKE %@",
[[@"*" stringByAppendingString:searchHotelNameString] stringByAppendingString:@"*"]];
searchHotelNameString
如果您使用
like
运算符(operator)。
==
而不是使用
LIKE
如果您不使用正则表达式:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF['@HName'] == %@",
searchHotelNameString];
NSString *searchHotelNameString = @"Taj Palace";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF['@HName'] == %@",
searchHotelNameString];
NSArray *arrHotelResults = @[
@{@"@HIndex" : @5, @"@HName" : @"XYZ Plaza Hotel Dubai", @"@Lattitude" : @25.2174},
@{@"@HIndex" : @5, @"@HName" : @"Beijing", @"@Lattitude" : @25.2174},
@{@"@HIndex" : @5, @"@HName" : @"Xiamen", @"@Lattitude" : @25.2174},
@{@"@HIndex" : @5, @"@HName" : @"Wuhan", @"@Lattitude" : @25.2174},
@{@"@HIndex" : @5, @"@HName" : @"Taj Palace", @"@Lattitude" : @25.2174}
];
NSArray *resultObjectsArray = [arrHotelResults filteredArrayUsingPredicate:predicate];
NSLog(@"%@", resultObjectsArray);
关于ios - [<__NSCFDictionary 0x7fdf8a926250> valueForUndefinedKey :]: this class is not key value coding-compliant for the key HName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31072159/
我是一名优秀的程序员,十分优秀!