2

I get this warning in Xcode

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

it is in the Core Data Ensembles Framework in

CDEICloudFileSystem.m

in

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

Can someone tell me how to fix this ?

Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Kreuzberg
  • 894
  • 1
  • 9
  • 18
  • Unless you are attempting to support iOS 5, there is no need to check for the `NSUbiquityIdentityDidChangeNotification` constant. – rmaddy Nov 04 '15 at 22:51

2 Answers2

2

The problem is that &NSUbiquityIdentityDidChangeNotification is the address of the variable and it cannot be NULL. The condition if (&NSUbiquityIdentityDidChangeNotification != NULL) always values true and Xcode warns you that the line is useless.

Jeremy Vizzini
  • 261
  • 1
  • 9
  • 1
    The address can be `NULL` if run under iOS 5 or earlier. – rmaddy Nov 04 '15 at 22:52
  • I support iOS7 and later. So I can just delete the line ? It s just, it s not my code, and I am afraid to mess with the framework :/ – Kreuzberg Nov 04 '15 at 22:58
  • Yes you have to delete `if (&NSUbiquityIdentityDidChangeNotification != NULL) {` – Jeremy Vizzini Nov 04 '15 at 22:59
  • @JeremyVizzini It's not that you have to delete it. It's that it's pointless in this case. – rmaddy Nov 04 '15 at 23:04
  • @Kreuzberg If you prefer not removing the code from the implementation file, write the expression as follows: ((&NSUbiquityIdentityDidChangeNotification) != NULL). This will remove the warning in Xcode 7. Just another option. – Nathan B. Nov 05 '15 at 04:04
2

I wrote that code. As several have pointed out, it is there to ensure that the NSUbiquityIdentityDidChangeNotification symbol exists before using it. Before iOS 6, that notification did not exist.

The code is several years old, and iOS 5 is not supported now in the framework, so I will remove the check.

Update Turns out the check could not be removed, because we still support OS X 10.7. So I added #pragmas to silence the warning instead.

Drew McCormack
  • 3,490
  • 1
  • 19
  • 23
  • Thanks ! My app is iOS only and supports iOS7 and later, no OS X - so I am just gonna remove the line... !? – Kreuzberg Nov 05 '15 at 13:49