【问题标题】:Comparison of addresses of NSUbiquityIdentityDidChangeNotification not equal to a null pointer is always trueNSUbiquityIdentityDidChangeNotification 不等于空指针的地址比较总是为真
【发布时间】:2015-11-04 22:41:39
【问题描述】:

我在 Xcode 中收到此警告

comparison of addresses of NSUbiquitycontainerDidChangeNotification not equal to a null pointer is always true

它在核心数据集成框架中

CDEICloudFileSystem.m

- (void)addUbiquityContainerNotificationObservers  {

 [self removeUbiquityContainerNotificationObservers];

/// in this line 
if (&NSUbiquityIdentityDidChangeNotification != NULL) {
///

    __weak typeof(self) weakSelf = self;
    ubiquityIdentityObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSUbiquityIdentityDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        [strongSelf stopMonitoring];
        [strongSelf willChangeValueForKey:@"identityToken"];
        [strongSelf didChangeValueForKey:@"identityToken"];
    }];
  }
}

谁能告诉我如何解决这个问题?

谢谢

【问题讨论】:

  • 除非您尝试支持 iOS 5,否则无需检查 NSUbiquityIdentityDidChangeNotification 常量。

标签: ios objective-c ensembles


【解决方案1】:

我写了那个代码。正如一些人指出的那样,它可以确保NSUbiquityIdentityDidChangeNotification 符号在使用之前存在。在 iOS 6 之前,该通知不存在。

代码有几年了,现在框架不支持iOS 5,所以我将取消勾选。

更新 原来检查无法删除,因为我们仍然支持 OS X 10.7。所以我添加了#pragmas 来消除警告。

【讨论】:

  • 谢谢!我的应用程序仅支持 iOS 并支持 iOS7 及更高版本,没有 OS X - 所以我要删除该行...!?
【解决方案2】:

问题是&NSUbiquityIdentityDidChangeNotification是变量的地址,不能为NULL。 条件if (&NSUbiquityIdentityDidChangeNotification != NULL) 总是值 true 并且 Xcode 警告您该行是无用的。

【讨论】:

  • 如果在iOS 5或更早版本下运行,地址可以是NULL
  • 我支持 iOS7 及更高版本。所以我可以删除该行吗?只是,这不是我的代码,我怕乱了框架:/
  • 是的,你必须删除if (&NSUbiquityIdentityDidChangeNotification != NULL) {
  • @JeremyVizzini 这不是你必须删除它。就是在这种情况下是没有意义的。
  • @Kreuzberg 如果您不想从实现文件中删除代码,请编写如下表达式:((&NSUbiquityIdentityDidChangeNotification) != NULL)。这将删除 Xcode 7 中的警告。只是另一种选择。
猜你喜欢
  • 2023-02-01
  • 1970-01-01
  • 2022-12-09
  • 2011-02-15
  • 1970-01-01
  • 1970-01-01
  • 2021-12-10
  • 2013-05-09
  • 2018-04-22
相关资源
最近更新 更多