【问题标题】:How to search nsmutablearray in objective c-iPhone app如何在目标 c-iPhone 应用程序中搜索 nsmutablearray
【发布时间】:2009-06-29 08:21:52
【问题描述】:

我正在将 RSS 提要读入 nsmutablearray。我想搜索 xml 提要。为此,我想搜索 nsmutablearray。我对 iPhone 应用程序非常陌生。有人可以帮我解决这个问题吗..

谢谢,

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    您可以使用谓词“搜索”数组,如下所示:

    NSMutableArray* names = [NSMutableArray arrayWithObjects:@"Andy", @"Bart", @"Bob", nil]; 
    NSPredicate* predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'b'"];
    NSArray* namesStartingWithB = [names filteredArrayUsingPredicate: predicate];
    // namesStartingWithB now contains @"Bart" & @"Bob"
    

    您应该查看NSArrayNSPredicate 文档以获取更多信息。如果您需要解析 XML 的特定信息(即 RSS 提要),您应该查看 Matt Gallagher 在using libxml2 for XML parsing and XPath queries in Cocoa 上的文章。

    【讨论】:

    • 不应该 NSArray* namesStartingWithB = [array filteredArrayUsingPredicate: predicate];是 NSArray* namesStartingWithB = [names filteredArrayUsingPredicate: predicate];
    • @James 感谢您的提醒——已修复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    • 2010-12-24
    • 2013-05-28
    • 1970-01-01
    • 2014-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多