i think this is not tought but i'm facing problem with these. i am fecthing core date and after fetching it i'm trying to save it into nsarray. but every time last data from database is saving into array. i want every data inserted into databases. suppose i have an attribute name account_name i added A,B,C,X,Y,Z. in this code i'm just getting last value Z in my array. :( but when i print it then i'm getting all data.. any solution ?
NSArray *fetchedObjects;
AppDelegate *delegate = [UIApplication sharedApplication].delegate;
NSManagedObjectContext *context = [delegate managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Chart_of_Accounting" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSError *error;
fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *obj in fetchedObjects) {
debitArray = [NSMutableArray arrayWithObject:[obj valueForKey:@"account_name"]];
creditArray = [NSMutableArray arrayWithObject:[obj valueForKey:@"account_name"]];
NSLog(@"Account Name: %@", [obj valueForKey:@"account_name"]);
}