连字符在NSDictionary键中

时间:2009-11-19 23:37:16

标签: objective-c nspredicate

我已经工作了几天而没有运气。我试图从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>

1 个答案:

答案 0 :(得分:3)

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

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