2015-11-04 79 views
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"]; 
    }]; 
    } 
} 

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

感谢

+0

除非您尝试支持iOS 5,否则不需要检查'NSUbiquityIdentityDidChangeNotification'常量。 – rmaddy

回答

2

我写了这段代码。正如几位已经指出的那样,在使用之前确保存在NSUbiquityIdentityDidChangeNotification符号。在iOS 6之前,该通知不存在。

代码已有几年了,现在框架中不支持iOS 5,所以我将删除该支票。

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

+0

谢谢!我的应用程序仅适用于iOS,并且支持iOS7及更高版本,无OS X - 所以我只是要删除该行......! – Kreuzberg

2

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

+1

如果在iOS 5或更低版本下运行,地址可以为NULL。 – rmaddy

+0

我支持iOS7及更高版本。所以我可以删除该行?这只是,它不是我的代码,我很害怕这个框架:/ – Kreuzberg

+0

是的,你必须删除'if(&NSUbiquityIdentityDidChangeNotification!= NULL){' –