【发布时间】:2013-07-02 19:19:40
【问题描述】:
迁移到 ARC 时出现上述错误。代码如下:
static NSString *cashBalanceKeyPath = @"test";
...
[xxx forKeyPath:cashBalanceKeyPath options:NSKeyValueObservingOptionNew context:&cashBalanceKeyPath];
...
-(void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if (&cashBalanceKeyPath == context) < error here
{
...
}
当我使用桥接器时:
if (&cashBalanceKeyPath == (__bridge NSString *)context)
我收到了错误:Comparison of distinct pointer types (NSString *__strong* and NSString *)
如何进行转换?提前致谢。
【问题讨论】:
-
这个比较是否适用于 MRC?
-
是的。比较适用于 MRC(没有 ARC)。可以隐式转换。
-
原始比较
&cashBalanceKeyPath == context即使在 ARC 下也看起来不错。您没有比较任何对象,甚至没有将对象转换为普通指针。原来的编译错误是什么?
标签: ios objective-c cocoa automatic-ref-counting