I have developed a application where i have a method that used managed object context of core data framework to load its content to data base. I am calling that method in the did finish launching method of delegate. and I am using a UITableView to fetch the data and displaying it in the table view. My problem is the same data is displaying twice in the table view.
When i launch the application using Xcode the data is displaying only one time and then after stopping the xcode and when i open the application for the first time in the device i am getting the duplicate copy of the same data. I am not getting how to avoid this duplication please help me with this.
-(void) devicedetails
{
devicename = [UIDevice currentDevice].name;
osversion = [UIDevice currentDevice].systemVersion;
//some other data like this
NSManagedObjectContext context = [self managedObjectContext];
Deviceinfo *detail = [NSEntityDescription insertNewObjectForEntityForName:@"Deviceinfo" inManagedObjectContext:nscontext];
detail.platform = devicename;
detail.os_version = devosversion;
.
.
.
}
This is my method and i called it in didfinish launching method like below
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self devicedetails];
return YES;
}
Thanks
You are inserting a new object every time you call
-insertNewObjectForEntityForName:inManagedObjectContext:.What you should do is to try and fetch the object before inserting it. If the fetch is empty then insert the new object, otherwise don’t insert it.