ios - RaptureXML 迭代 :usingBlock warning and crash

标签 ios xml nsarray loops

我正在解析一个如下所示的 XML 文件:

<partie numero="1">
      <exercice numero="1" libelle="blabla"></exercice>
      <exercice numero="2" libelle="anything"></exercice>
</partie>

我正在使用 Rapture XML 库,因此如 GitHub 上所述,我执行以下操作:

RXMLElement *rxmlPartie = [rxmlParties child:@"partie"];
NSArray *rxmlUnExercice = [rxmlPartie children:@"exercice"];

我可以使用这一行从 partie 中正确打印“numero”属性:

 NSLog(@"Partie #%@",[rxmlPartie attribute:@"numero"] );

但是当我尝试在我的 NSArray 上使用迭代方法时:

[rxmlPartie iterate:@"partie.exercice" usingBlock: ^(RXMLElement *exercice) {NSLog(@"Exercice: %@ (#%@)", [exercice attribute:@"libelle"], [exercice attribute:@"numero"]);}];

我收到一条警告,应用程序崩溃,说:

-[RXMLElement iterate:usingBlock:]: unrecognized selector sent to instance 0xc67f870
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-    [RXMLElement iterate:usingBlock:]: unrecognized selector sent to instance 0xc67f870'

我是否忘记导入某些东西,或者我是否以错误的方式实现了该方法?

如果我尝试使用 iterateWithRootXPath 会发生同样的错误...

感谢您的帮助!

最佳答案

所以,我发现了我的问题所在。

在执行此操作之前,我对使用 Rapture XML 进行配对一无所知……所以我坚持使用文档(就像有人在学校告诉我的那样 :-))。但问题是文档中使用的方法,这个“iterate usingBlock”在框架中没有定义。

而不是使用

[rxmlPartie iterate:@"partie.exercice" usingBlock: ^(RXMLElement *exercice)     {NSLog(@"Exercice: %@ (#%@)", [exercice attribute:@"libelle"], [exercice attribute:@"numero"]);}];

我在用

[rxmlPartie iterate:@"exercice" with: ^(RXMLElement *exercice)     {NSLog(@"Exercice: %@ (#%@)", [exercice attribute:@"libelle"], [exercice attribute:@"numero"]);}];

框架内定义明确!

这让我很开心!!

关于ios - RaptureXML 迭代 :usingBlock warning and crash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10735145/

相关文章:

ios - 我可以为非 NSString 数据类型匹配 NSPredicate 吗?

xml - 从多个 xml 文件中提取节点

android - Android 和 iOS 在 Intent 和后台操作方面的差异

ios - 过滤器功能在这种情况下不起作用?

ios - Objc 中的 SecRandomCopyBytes 提供程序(SHA1PRNG 或 NativePRNG)类型?

android - 当我尝试设置 fontFamily 属性时,为标签 TextView 找到意外的命名空间前缀 "app"

xml - XPATH:子节点上的总和不是整个 XPATH

objective-c - 使用组件分离形成 NSArray 并使用重复元素形成另一个数组

ios - 如何在 NSMutableArray 中对对象进行分组并在 Objective-C 中划分为单独的 NSMutableArray

ios - 从数组中删除重复的项目并保留最后出现的项目 - iOS