【问题标题】:hyphen in NSDictionary keyNSDictionary 键中的连字符
【发布时间】:2010-08-11 12:24:13
【问题描述】:

我已经工作了几天了,但没有运气。我正在尝试从 NSDicitonary 解析一组键/值对,但它似乎对键名中的连字符非常敏感。下面是数据示例。如果我尝试使用下面的代码访问带有连字符的任何字段,则会收到以下错误:

无法识别的选择器发送到实例

有什么建议吗?

NSString *param = [[NSString alloc] initWithFormat:@" url-name like %@",url ];   
NSPredicate *predicate = [NSPredicate predicateWithFormat:param]; 
NSArray *results = [aCompanies filteredArrayUsingPredicate:predicate];

<company>
    <address-one></address-one>
    <address-two></address-two>   
    <city></city>
    <country></country>
    <id type="integer">11899</id>
    <name>Aceara</name>
    <phone-number-fax></phone-number-fax>
    <phone-number-office></phone-number-office>
    <state></state>
    <time-zone-id>Central Time (US &amp; Canada)</time-zone-id>
    <url-name>ACEARA</url-name>
    <uuid>7cc52da5-6783-4c59-9c60-b8fe96f2110c</uuid>
    <web-address>WWW.ACEARA.COM</web-address>
    <zip></zip>    
    <can-see-private type="boolean">false</can-see-private>
</company>

【问题讨论】:

  • 无需分配字符串,然后将其分配为谓词的格式。直接创建谓词即可:NSPredicate *predicate = [NSPredicate predicateWithFormat:@"'url-name' like '%@'",url];

标签: objective-c nspredicate


【解决方案1】:

用引号括住字符串以避免出现问题,例如:

initWithFormat:@"'url-name' like '%@'"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    相关资源
    最近更新 更多