2

我在 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"];
    }];
  }
}

有人可以告诉我如何解决这个问题吗?

谢谢

4

2 回答 2

2

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

于 2015-11-04T22:51:54.823 回答
2

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

代码几年了,现在框架不支持iOS 5,所以我将删除检查。

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

于 2015-11-05T07:35:07.197 回答