简体   繁体   中英

Getting error like “Implicit declaration of function 'IS_NOT_NIL_OR_NULL' is invalid in C99”

When i am trying to restrict nill value in coredata i am getting error like

Implicit declaration of function 'IS_NOT_NIL_OR_NULL' is invalid in C99

Here is my code:

 if ([[context executeFetchRequest:fetchRequest error:NULL] count] == 0) {
        // Create a new managed object
        NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"demo" inManagedObjectContext:context];
         if (IS_NOT_NIL_OR_NULL(self.Name))
    {
        [newDevice setValue:self.Name forKey:@"nameofentry"];
    } else 
     {
        // Handle else case .  get self.name value is null here .

     }

         if (IS_NOT_NIL_OR_NULL(self.WebsiteName))
    {
        [newDevice setValue:self.WebsiteName forKey:@"sitename"];
    } else 
     {
        // Handle else case .  get self.WebsiteName value is null here .

     }


          if (IS_NOT_NIL_OR_NULL(self.Feedlink))
    {
        [newDevice setValue:self.Feedlink forKey:@"urloffeed"];
    } else 
     {
        // Handle else case .  get self.Feedlink value is null here .

     }

        NSError *error = nil;
        // Save the object to persistent store
        if (![context save:&error]) {
            NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
        }

    }

EDIT:

在此处输入图片说明

在此处输入图片说明

Based on the referenced question and the answers where you found the reference to IS_NOT_NIL_OR_NULL , I'm guessing that one possible solution is to define the macro as:

#define IS_NOT_NIL_OR_NULL(x) (x && x != (id)[NSNull null])

Add this to the top of the .m file just after the import statements or add it to a common .h file that you can import.

Then code such as:

if (IS_NOT_NIL_OR_NULL(self.WebsiteName)) {

will become:

if ((self.WebsiteName && self.WebsiteName != (id)[NSNull null])) {

which I believe is what you are looking for.

它只是一个宏定义。

 #define IS_NOT_NIL_OR_NULL(value)           (value != nil && value != Nil && value != NULL && value != (id)[NSNull null])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM