Q:

Insert data using Core Data

i am using following written code to insert bulk data using core data technique...
Please tell me is it right approach to do the same...I am taking context and entity object inside the loop...if taken outside only last element of arrays gets inserted...Please advise...
DataGetSet *objDataGetSet=nil;
NSManagedObjectContext *context=nil;

for(int i=0;i<[arrTemp count];i++)
{
  context = [obj_delegate managedObjectContext];

  NSManagedObject *propertyInfo = [NSEntityDescription
                   insertNewObjectForEntityForName:@"Property" 
                   inManagedObjectContext:context];

  objDataGetSet=[arrTemp objectAtIndex:i];

  [propertyInfo setValue:[objDataGetSet code] forKey:@"Code"];
  [propertyInfo setValue:[objDataGetSet location] forKey:@"Location"];
  [propertyInfo setValue:[objDataGetSet ownershipType] forKey:@"OwnershipType"];
  [propertyInfo setValue:[objDataGetSet price] forKey:@"Price"];
  [propertyInfo setValue:[objDataGetSet propertyType] forKey:@"PropertyType"];
  [propertyInfo setValue:[objDataGetSet size] forKey:@"Size"];  
}
NSError *error;
if (![context save:&error]) {
  NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}

A:

Yes, thats correct. But it could be better:
First of all, it's not that good to take manageObjectContext from appDelegate. You can pass it to your rooViewController class manually from AppDelegate's method, for example like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    if ( !managedObjectContext_ )
    {
       [self createManagedObjectContext]; // you should write this method(create and insert your enities)
    }

    self.yourRootViewControllerClass.managedObjectContext_ = self.managedObjectContext;
    self.window.rootViewController = self.yourRootViewControllerClass;
    [self.window makeKeyAndVisible];

    return YES;
}

Then (if you have sub ViewControllers) you have to pass your managedObjectContext from your rootViewController class in the same manner like from AppDelegate.
One more thing is that you can make a managedObject subclass, and then you'll be able to get and set properties in an easier manner (not [propertyInfo setValue:[objDataGetSet code] forKey:@"Code"] but just propertyInfo.Code = [objDataGetSet code]
You can read about how-to do it clearly here.

