Home > Software engineering >  How to call NSArray's enumerateObjectsUsingBlock in lldb?
How to call NSArray's enumerateObjectsUsingBlock in lldb?

Time:12-10

I want to call enumerateObjectsUsingBlock print each object in a array when debugging. But the lldb seems can't support block ? Is there anyway to make this working ?

(lldb) expr -- [self.choiceQuestion.allNewRecommenedItems enumerateObjectsUsingBlock:void ^(id obj,NSUInteger index,BOOL* stop){NSLog(@"%@",obj);}]
error: <user expression 9>:1:76: expected '(' for function-style cast or type construction
[self.choiceQuestion.allNewRecommenedItems enumerateObjectsUsingBlock:void ^(id obj,NSUInteger index,BOOL* stop){NSLog(@"%@",obj);}]

CodePudding user response:

If I put your example in a source file - to eliminate possible problems with the expression parser - I get the same syntax error you were showing. So apparently this isn't legal block syntax. But then if I try (just removing the void):

[myArr enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSLog(@"%@", obj); }];

that successfully compiles. Unsurprisingly, that expression also works in the expression evaluator.

I suspect that since the compiler infers the type of the block from the return value of its body, the return type specification is not allowed, but you'd have to find somebody more familiar with the details of block syntax to say for sure.

CodePudding user response:

Thanks JimIngham's answer. A specific answer to print array in lldb will like this:

(lldb) expr -- [self.choiceQuestion.allNewRecommenedItems  enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {(void)NSLog(@"11");}]
  • Related