这样的事情在调试时让我发疯:
(lldb) p self.bounds
error: unsupported expression with unknown type
error: unsupported expression with unknown type
error: 2 errors parsing expression
(lldb) p (CGRect)self.bounds
error: unsupported expression with unknown type
error: unsupported expression with unknown type
error: C-style cast from '<unknown type>' to 'CGRect' is not allowed
error: 3 errors parsing expression
(lldb) p [self bounds]
error: 'bounds' has unknown return type; cast the call to its declared return type
error: 1 errors parsing expression
(lldb) p (CGRect)[self bounds]
(CGRect) $1 = origin=(x=0, y=0) size=(width=320, height=238)
(lldb) You suck!
error: 'You' is not a valid command.
(lldb) …
Run Code Online (Sandbox Code Playgroud)
前三次尝试失败的原因是什么?有没有更简单的打印方式self.bounds?谢谢.
you*_*ufu 53
你可以访问它
p (CGRect)[view bounds]
Run Code Online (Sandbox Code Playgroud)
要么
p view.layer.bounds
Run Code Online (Sandbox Code Playgroud)
view.bounds 实际上是 view.layer.bounds
似乎类型信息[UIView bounds]不可用lldb
onm*_*133 13
你会喜欢Xcode 6.3+
TLDR
(lldb) e @import UIKit
(lldb) po self.view.bounds
Run Code Online (Sandbox Code Playgroud)
LLDB的Objective-C表达式解析器现在可以导入模块.任何后续表达式都可以依赖于模块中定义的函数和方法原型:
(lldb) p @import Foundation
(lldb) p NSPointFromString(@"{10.0, 20.0}");
(NSPoint) $1 = (x = 10, y = 20)
Run Code Online (Sandbox Code Playgroud)
在Xcode 6.3之前,没有调试信息的方法和函数需要显式类型转换来指定它们的返回类型.导入模块允许开发人员避免手动确定和指定此信息的人工密集程序:
(lldb) p NSPointFromString(@"{10.0, 20.0}");
error: 'NSPointFromString' has unknown return type; cast the call to its declared return type
error: 1 errors parsing expression
(lldb) p (NSPoint)NSPointFromString(@"{10.0, 20.0}”);
(NSPoint) $0 = (x = 10, y = 20)
Run Code Online (Sandbox Code Playgroud)
导入模块的其他好处包括更好的错误消息,在64位设备上运行时对可变参数函数的访问,以及消除可能不正确的推断参数类型.
PS:如果你也混淆p vs po
p == print == expression -- == e --
po == expression -O -- == e -O --
Run Code Online (Sandbox Code Playgroud)
--是command+flagvs 之间的分隔符inputs
-Oflag用于调用object description方法
LLDB在使用时不支持用于消息发送的点表示法p,这就是原因
p self.bounds
Run Code Online (Sandbox Code Playgroud)
不起作用,但是
p [self bounds]
Run Code Online (Sandbox Code Playgroud)
确实.
(但实际上,它在使用时支持对象po)
此外,LLDB没有在运行时可用的非对象的类型信息,因此您需要通过强制转换返回值来显式提供类型.
使用Xcode 6.3,我们可以导入UIKit,然后打印框架或视图边界
expr @import UIKit
p self.view.bounds
Run Code Online (Sandbox Code Playgroud)