【问题标题】:ARC conversion : iphone implicit conversion of 'BOOL' (aka 'signed char') to 'id' is disallowed with ARCARC 转换: ARC 不允许 iPhone 将“BOOL”(又名“signed char”)隐式转换为“id”
【发布时间】:2011-10-16 09:42:24
【问题描述】:
Implicit conversion of 'BOOL' (aka 'signed char') to 'id' is disallowed with ARC

这是我在尝试使用自动化工具将一些代码迁移到 ARC 时遇到的错误

[[NSNotificationCenter defaultCenter] addObserver:self  
                                      selector:@selector(vDidFinish)
                                      name:aNotifName
                                      object:NO];

如何确保它符合 ARC 要求?

【问题讨论】:

    标签: iphone ios5 automatic-ref-counting


    【解决方案1】:

    您应该为第四个参数(通知发送者)使用正确的类型。它需要一个 Objective-C 对象——如果你不想指定一个,传递 nil 而不是 NO;后者是 BOOL 类型的文字值。

    【讨论】:

    • 让我补充一点,如果您的意图实际上是让对象成为值为 NO 的布尔值,那么您可以将其装箱为 NSNumber:[NSNumber numberWithBool:NO]
    • @Jean 但是NSNumber 不会发布通知。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-11
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多