title: Getting Null Value From Database NSManagedObject
body: <p>I am developing iOS app, which fetch data from Web Services and save it to local database and uses it various views as needed. The data is fetch from Web Service and save to database correctly. But while accessing data from <code>NSManagedObject</code> it show <code>FAULT</code> and the consequent <code>NSDictionary</code> shows <code>null</code> Values </p>
  
  <p>The code follows:-  </p>
  
  <pre><code>-(void)SaveData:(NSInteger)menuId categoryID:(NSInteger)catID   caption:(NSString *)title parentID:(NSInteger)parentID
  {
      BBAppDelegate *appDelegate = [[BBAppDelegate alloc]init];
  
      NSManagedObjectContext *context = [appDelegate managedObjectContext];
  
      NSManagedObject *userobj = [NSEntityDescription insertNewObjectForEntityForName:tableName
                                                               inManagedObjectContext:context];
      [userobj setValue:[NSNumber numberWithInt:menuId] forKey:@"id"];
  
      [userobj setValue:[NSNumber numberWithInt:catID] forKey:@"catid"];
  
      [userobj setValue:[NSNumber numberWithInt:parentID] forKey:@"parentid"];
  
      [userobj setValue:title forKey:@"caption"];
  
      NSError *error = nil;
      // Save the object to persistent store
      if (![context save:&amp;error]) {
          NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
      }
  
      NSLog(@"app dir: %@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);
  }
  -(NSArray *)fetchedData{
  
      BBAppDelegate *appdelegate = [[BBAppDelegate alloc]init];
  
      NSManagedObjectContext *context = [appdelegate managedObjectContext];
  
      NSFetchRequest *readData = [[NSFetchRequest alloc] init];
  
      [readData setReturnsObjectsAsFaults:NO];
  
  
      NSEntityDescription *entity = [NSEntityDescription
                                     entityForName:tableName inManagedObjectContext:context];
  
      [readData setEntity:entity];
  
      NSError *error = nil;
  
      NSArray *results = [context executeFetchRequest:readData error:&amp;error];
  
  //    for (Test *test in array)
  //    {
  //        NSLog(@"Test: %@ ", test.text);
  //    }
  
      NSLog(@"%@",results);
  
      return results;
  
  }
  -(void)removeData{
  
      BBAppDelegate *appdelegate = [[BBAppDelegate alloc]init];
  
      NSManagedObjectContext *context = [appdelegate managedObjectContext];
  
      NSFetchRequest *delData = [[NSFetchRequest alloc]init];
  
      [delData setEntity:[NSEntityDescription entityForName:tableName inManagedObjectContext:context]];
  
      [delData setIncludesPropertyValues:NO];
  
      NSError *error = nil;
  
      NSArray *result = [context executeFetchRequest:delData error:&amp;error];
  
      for (NSManagedObject *value  in result) {
          [context deleteObject:value];
      }
      NSError *saveError = nil;
  
      [context save:&amp;saveError];
  }
  -(void)table:(NSString *)nameTable{
  
      tableName =nameTable;
  }
  - (instancetype)initWithTableName:(NSString *)tablename
  {
      [self table:tablename];
  
      return self;
  }
  -(NSMutableArray *)buldMenu{
  
      NSArray *array = [self fetchedData];
  
      return [self getmenus:0 arr:array];
  }
  -(NSMutableArray *)getmenus:(NSInteger)parentID arr: (NSArray *)array
  {
      NSMutableArray *aray = [[NSMutableArray alloc]init];
  
      for (NSManagedObject *dic in array) {
  
          if (dic.faultingState != 0) {
  
              NSLog(@"%lu",(unsigned long)dic.faultingState);
  
              //return nil;
          }
  
          NSArray *keys = [[[dic entity] attributesByName] allKeys];
  
          NSLog(@"%@",keys);
  
          NSDictionary *dict = [dic dictionaryWithValuesForKeys:keys];
          NSLog(@"%@",dic);
  
          NSLog(@"%@",dict);
  
  
          NSInteger pID = [[dict  objectForKey:@"parentid"]integerValue];
  
          if (pID == parentID) {
              BBMenuEntry *entryMenu = [[BBMenuEntry alloc]init];
              entryMenu.menuID = [[dict objectForKey:@"id"]integerValue];
              entryMenu.catID = [[dict objectForKey:@"catid"]integerValue];
              entryMenu.caption = [dict objectForKey:@"caption"];
              entryMenu.subMenus = [self getmenus:entryMenu.menuID arr:array];
  
              [aray addObject:entryMenu];
  
          }
      }
      return aray;
  }
  </code></pre>