-1

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:

enter image description here

enter image description here

2 Answers2

2

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.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
rmaddy
  • 314,917
  • 42
  • 532
  • 579
0

it just a macros defeine as .

 #define IS_NOT_NIL_OR_NULL(value)           (value != nil && value != Nil && value != NULL && value != (id)[NSNull null])
Garry
  • 407
  • 2
  • 15
  • 1
    Checking `nil`, `Nil`, and `NULL` is redundant. Those are all the same. You only need one of those plus the `[NSNull null]` check. – rmaddy Oct 27 '15 at 05:40
  • @rmaddy check this out http://stackoverflow.com/questions/5908936/difference-between-nil-nil-and-null-in-objective-c – Garry Oct 27 '15 at 05:49
  • Yes, that verifies what I'm saying. – rmaddy Oct 27 '15 at 05:50