2016-01-29 42 views
1

在XCTest期间(后来在正常运行期间)处于断点时,我遇到了......奇怪的事情。我想下面的截图说明我的问题:为什么我不能使用LLDB打印出一个带字符的字符串?

Two calls of the LLDB, one reading <code>po @"12"</code>, with the successful print below reading <code>12</code>. The next is <code>po @"\u0031\u0032"</code> and also prints <code>12</code>. The next reads <code>po @"12¢"</code>, with an error below saying "An Objective-C constant string's string initializer is not an array". The third reads <code>po @"\u0031\u0032\u00A2"</code>, the fourth reads <code>po @"¢"</code>, and the fifth <code>po @"\u00A2"</code> and all have the same issue.

为什么它要求An Objective-C constant string's string initializer is not an array它看起来好像它试图将我的@""NSString文字糖翻译成NSString初始化器与C字符串不成功,但为什么?

此外,我用¢字符或其Unicode转义序列测试了许多其他字符串,它们都具有相同的结果。

回答

2

这看起来像一个错误。请用http://bugreporter.apple.com提交。

静态字符串构造涉及到一些编译器的魔力,当字符串包含高位字符时,显然lldb没有得到正确的结果。您可以通过使用NSString的构造函数的一个实现在表达式解析器相同的效果:

(lldb) expr NSString *$newstr = [NSString stringWithUTF8String: "Something¢"] 
(lldb) expr $newstr 
(__NSCFString *) $newstr = 0x00000001007000a0 @"Something¢" 

然后你就可以在未来的表达式中使用$中newstr。

+0

这里需要注意的一点是,NSString构造函数会返回自动释放的对象,所以如果您想将此字符串分配给程序中的某个指针,您需要在将它传回ARC世界之前保留它,否则它将被释放并变坏。如果你只是在lldb中的表达式中使用它,那么这是不必要的。 –

相关问题