在LLDB中不能传递CGColorRef类型的参数

时间:2015-08-04 13:23:15

标签: objective-c core-graphics lldb core-foundation

我正在扩展Facebook的Chisel,以便能够从调试器中显示颜色。我希望它适用于UIColorCIColorCGColorRef。这两个基于对象的工作正常,但CGColorRef给我带来了麻烦。

Here是我正在处理的错误,我已经从这个问题中删除了很多东西。

我已将问题归结为此测试用例:

如果我有一些功能:

+ (UIColor *)someColor {
    UIColor *uiColor = [UIColor redColor];
    CGColorRef cgColor = uiColor.CGColor;
    UIColor *newUIColor = [UIColor colorWithCGColor:cgColor];
    return newUIColor;
}

我在return newUIColor;行设置断点,这是LLDB中发生的事情:

(lldb) po cgColor
<CGColor 0x7f992b626710> [<CGColorSpace 0x7f992b70d5b0> (kCGColorSpaceDeviceRGB)] ( 0 0.478431 1 1 )

(lldb) po [UIColor colorWithCGColor:cgColor]
error: cannot initialize a parameter of type 'CGColor *' with an lvalue of type 'CGColorRef' (aka 'CGColor *')
error: 1 errors parsing expression
(lldb) po [UIColor colorWithCGColor:(CGColorRef)cgColor]
error: cannot initialize a parameter of type 'CGColor *' with an rvalue of type 'CGColorRef' (aka 'CGColor *')
error: 1 errors parsing expression
(lldb) po [UIColor colorWithCGColor:(id)cgColor]
error: cannot initialize a parameter of type 'CGColor *' with an rvalue of type 'id'
error: 1 errors parsing expression
(lldb) po [UIColor colorWithCGColor:(CGColor *)cgColor]
error: use of undeclared identifier 'CGColor'
error: expected expression
error: 2 errors parsing expression
(lldb) expr @import CoreGraphics
(lldb) po [UIColor colorWithCGColor:(CGColorRef)cgColor]
error: cannot initialize a parameter of type 'CGColor *' with an rvalue of type 'CGColorRef' (aka 'CGColor *')
error: 1 errors parsing expression
(lldb) po [UIColor colorWithCGColor:(CGColor *)cgColor]
error: cannot initialize a parameter of type 'CGColor *' with an rvalue of type 'CGColor *'
error: 1 errors parsing expression
(lldb) po [UIColor colorWithCGColor:(struct CGColor *)cgColor]
error: cannot initialize a parameter of type 'CGColor *' with an rvalue of type 'struct CGColor *'
error: 1 errors parsing expression

那么,我怎样才能让lldb执行一个采用CGColorRef类型参数的行?

1 个答案:

答案 0 :(得分:0)

我能够使用以下方式使用它:

(lldb) po [[UIColor alloc] initWithCGColor:cgColor]
UIDeviceRGBColorSpace 1 0 0 1

来自UIColor.h

@property(nonatomic,readonly) CGColorRef CGColor;
- (CGColorRef)CGColor NS_RETURNS_INNER_POINTER CF_RETURNS_NOT_RETAINED;

所以我相信UIColor超出了范围,.CGColor的内存不再有效。我可能需要复制它,但就我的目的而言,使用-initWithCGColor:可以正常工作。