如何在使用expr命令在XCode中使用LLVM进行调试时更改NSURL变量值?

问题描述:

在Xcode中,LLDB可在调试时通过expr命令更改变量值(请参见How to change variables value while debugging with LLVM in XCode?)。我用这个方法成功地改变一个字符串值,但是当我改变一个NSURL变量,以一个新的实例,我得到了一个错误:如何在使用expr命令在XCode中使用LLVM进行调试时更改NSURL变量值?

(lldb) expr url = [NSURL URLWithString:@"www.example.com"]; 
error: no known method '+URLWithString:'; cast the message send to the method's return type 
error: 1 errors parsing expression 

我怎么能更改URL到一个新的价值?谢谢。

+0

您是否包含'Foundation.framework'? – Raptor

+0

应该是:'[NSURL URLWithString:@“http://www.example.com”];'? – Raptor

+0

@Shivan Raptor 是的,我已经介入'Fondation.framework'; '[NSURL URLWithString:@“http://www.example.com”]'不起作用。 谢谢! – SFeng

您可以尝试明确铸造,即

expr url = (NSURL *)[NSURL URLWithString:@"www.example.com"]; 

因为LLDB有时无法获得的返回类型。例如,

// You should specify the return type here: 
expr (int)[UIApplication version] 

// instead of 
expr [UIApplication version]