-->

Display CoreData Records

2019-04-14 04:05发布

问题:

I create an application using Coredata. I create a XML file and store all data into XML file. Then using coredata I store them into Database.

Now I want to view the all records from core data. My application create a sqlite file. But if I use select command in sqlite, there is no records displayed. But it shows "no errors".

Is there any way to view my records from core data or from Sqlite?

回答1:

I faced the same issue, and need to investigated the sqlite db created by coredata. I used the free Sqlite database browser. http://sqlitebrowser.sourceforge.net/

And browsed to the path where the sqlite file is.



回答2:

display / List out all the objects currently in the database

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
    entityForName:@"UserInfo" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *info in fetchedObjects) {
    NSLog(@"First Name: %@", [info valueForKey:@"firstname"]);
    NSManagedObject *details = [info valueForKey:@"address"];
    NSLog(@"Zip: %@", [details valueForKey:@"zip"]);
}