2015-11-04 78 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){' –