Display CoreData Records

2019-04-14 03:34发布

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?

2条回答
叼着烟拽天下
2楼-- · 2019-04-14 04:24

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"]);
}
查看更多
再贱就再见
3楼-- · 2019-04-14 04:30

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.

查看更多
登录 后发表回答