3lvis / DATAStack

100% Swift Simple Boilerplate Free Core Data Stack. NSPersistentContainer
Other
214 stars 44 forks source link

Fetch Data #62

Closed kanumuri9593 closed 8 years ago

kanumuri9593 commented 8 years ago

Hi I am using Sync and your framework to save my JSON data

how to fetch my data fro the coredata I see no instructions of fetching data using DATAStack

can you please help me out

thank you

3lvis commented 8 years ago

@kanumuri9593 Hi!

Just use a NSFetchRequest as you normally would do. This is just a Core Data wrapper.

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:dataStack.mainContext];
[fetchRequest setEntity:entity];

NSError *error = nil;
NSArray *result = [dataStack.managedObjectContext executeFetchRequest:fetchRequest error:&error];

if (error) {
    NSLog(@"Unable to execute fetch request.");
    NSLog(@"%@, %@", error, error.localizedDescription);

} else {
    NSLog(@"%@", result);
}