I tried few core data example. So what I have right now, I am able to save data to my cstore and also able to retrieve it. My problem is like this I am fetching data from server and storing it. Next time when I fetch data from server I want to save only new data.
My save data and fetch data methods looks like:
-(NSArray *)getUserListFromDB {
NSEntityDescription *entitydesc = [NSEntityDescription entityForName:@"Subscribers" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entitydesc];
NSError *error;
NSArray *channelData = [context executeFetchRequest:request error:&error];
return channelData;
}
-(void)saveUserslListToDB:(SubscriberChannelListDataModel *) subscriberChannelList {
NSEntityDescription *entitydesc = [NSEntityDescription entityForName:@"Subscribers" inManagedObjectContext:context];
NSMutableArray *user = subscriberList;
for(int position = 0; position < channelList.count; position ++) {
NSManagedObject *newUser = [[NSManagedObject alloc] initWithEntity:entitydesc insertIntoManagedObjectContext:context];
UserDataModel *userData = [user objectAtIndex:position];
[newUser setValue: userData.userName forKeyPath:@"userName”];
[newUser setValue: userData.userId forKeyPath:@“userId”];
NSError *error;
[context save:&error];
NSLog(@"Data save ..");
}
}
Is there any one already faced same problem and have good solution?