“单步执行直到退出函数objc_exception_throw,它没有行号信息。”在目标c中使用枚举时

时间:2012-03-01 07:16:37

标签: objective-c exception enumeration

我发现了一个类似的问题,引发了相同的异常,但没有帮助。没有人回答:Getting "Single stepping until exit from function CALayerGetDelegate, which has no line number information." in iphone sdk

当程序为aa+a+

时有效的示例参数

当参数程序再次调用方法为aa+a+a时导致中断的示例参数。为什么呢?

这是我的代码:

+(NSSet *)variablesUsedInsideProgram:(id)program
{

    NSMutableSet *variablesUsed = [NSMutableSet setWithArray:program];
    //put the program into a mutable set then pop off everything else that is !a,!b,!c

    id objectReferenceFromVariablesUsed = nil;
    for(objectReferenceFromVariablesUsed in variablesUsed) //breaks here
    {
        if (!([objectReferenceFromVariablesUsed isEqual:@"a"] | [objectReferenceFromVariablesUsed isEqual:@"b"] | [objectReferenceFromVariablesUsed isEqual:@"c"]))
        {
            [variablesUsed removeObject:objectReferenceFromVariablesUsed];
        }
    }
    return [variablesUsed copy];
}

DEBUG打印出我得到的陈述:

(gdb) po program<__NSArrayI 0x68a7a00>(a,a,+,a,+,a)

所以我知道我的程序在变量a

中推送
(gdb) po variablesUsed
{(
    "+",
    a
)}

添加到NSMutableSet时程序的唯一值

我所知道的事情正在发生:

  

objectReferenceFromVariablesUsed = +,然后它从Set

中弹出      

(gdb)po变量使用{(a)}

     

回到循环然后休息。获取错误消息“单步执行直到退出函数objc_exception_throw,它没有行号信息.Catchpoint 2(抛出异常)。

有人知道可能导致这种情况的原因吗?

2 个答案:

答案 0 :(得分:2)

原始答案(以及Walt的有用评论):

您在枚举时修改集

  在Objective-C的快速枚举中不允许​​使用

。 - Walt Sellers 3月1日8:22


<强>更新

该怎么做:

更好的方法是将应删除的对象添加到新集合中,并使用-minusSet:删除新集合中的所有对象来更新原始集合(下面的文档)。从文档中注意对象被移除(一个新的集合返回)。

  

minusSet:

     

从接收集中移除另一个给定集合中的每个对象(如果存在)。

- (void)minusSet:(NSSet *)otherSet
     

<强>参数

     

otherSet

     

要从接收集中删除的对象集。


实际实施(修改代码)

要删除不是“a”,“b”或“c”的所有对象,首先要创建一个新的NSMutableSet(objectsToBeRemoved),用于添加应删除的对象。枚举原始集(variablesUsed)并查找应删除的对象时,将其添加到新集(objectsToBeRemoved)。在枚举之后,通过计算原始集减去要删除的对象集来删除应该删除的所有对象。

+(NSSet *)variablesUsedInsideProgram:(id)program
{
    NSMutableSet *variablesUsed = [NSMutableSet setWithArray:program];
    //put the program into a mutable set then pop off everything else that is !a,!b,!c

    NSMutableSet *objectsToBeRemoved = [[NSMutableSet alloc] init];

    id objectReferenceFromVariablesUsed = nil;
    for(objectReferenceFromVariablesUsed in variablesUsed)
    {
        if (!([objectReferenceFromVariablesUsed isEqual:@"a"] || 
              [objectReferenceFromVariablesUsed isEqual:@"b"] || 
              [objectReferenceFromVariablesUsed isEqual:@"c"]))
        {
            [objectsToBeRemoved addObject:objectReferenceFromVariablesUsed];
        }
    }

    return [[variablesUsed minusSet:objectsToBeRemoved] copy];
}

答案 1 :(得分:0)

修复!

  

+(NSSet *)variablesUsedInsideProgram:(id)程序   {

NSMutableSet *variablesUsed = [NSMutableSet setWithArray:program];
NSMutableSet *variablesUsed1 = [NSMutableSet setWithArray:program]; **//HERE**
//put the program into a mutable set then pop off everything else that is !a,!b,!c

id objectReferenceFromVariablesUsed = nil;
for(objectReferenceFromVariablesUsed in variablesUsed) //breaks here
{
    if (!([objectReferenceFromVariablesUsed isEqual:@"a"] | [objectReferenceFromVariablesUsed isEqual:@"b"] | [objectReferenceFromVariablesUsed isEqual:@"c"]))
    {

        [variablesUsed1 removeObject:objectReferenceFromVariablesUsed];
    }
}
return [variablesUsed1 copy];

}