XCode4 - where to look for sqlite file created by core data

谁说胖子不能爱 提交于 2019-12-30 02:19:05

问题


I have just started using core data. I want to setup a pre-populated db. I read somewhere that core data creates a sqlite file when a core data app is run. I don't know where to look for it though.

I followed the instructions over on this blog but did not find the sqlite file over the location specified directory /Users/<Username>/Library/Application Support/iPhone Simulator/User/Application/<Application GUID>/Documents/<database name.sqlite> nor in the application directory.

here is my code for persistentCoordinator.

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil)
    {
        return __persistentStoreCoordinator;
    }

    NSString *storePath = [[[self applicationDocumentsDirectory] path] stringByAppendingPathComponent:@"coredata.sqlite"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath:storePath]) {
        NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"coredata" ofType:@"sqlite"];
        if (defaultStorePath) {
            [fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
        }
    }

    NSURL *storeURL = [NSURL fileURLWithPath:storePath];
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
    {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }    

    return __persistentStoreCoordinator;
}

回答1:


Those files are in ~/Library/Application Support/iPhone Simulator/[SDK version]/Applications/[App GUID]/Documents for me, both for Xcode 3 and Xcode 4.

If you have multiple SDKs, make sure to look in all the different SDK version directories for your app.




回答2:


For me it was in whatMuregSaid/[Application Guid]/Library/Application Support/[AppName]/filename.sqlite




回答3:


Follow these steps:

  1. In your applicationDocumentsDirectory function in AppDelegate.swift add this code:

    let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)

    // Look for this in the console, this will print out the location of the sqlite database, which you can then open with an SQLite viewer

    print("urls.last \(urls.last)")

  2. Look for this in the console, this will print out the location of the sqlite database, open your terminal and open whatever_the_location_path_was

  3. Download SQLite viewer http://sqlitebrowser.org/

  4. Right click the yourapp.sqlite file in the folder, choose Open With sqlitebrowser that you downloaded

Cheers!




回答4:


hope this will help you little more

  1. /Users/Username/ then press cmd+shift+G and write /Users/Username/Library, Now you will see Library folder after it go to Application Support/iPhone Simulator/7.1(or 7.1-64)/Applications/F84D4CC8-326E-4A2E-8A37-F1A755D6FCC4/Documents you will see three file and one is .sqlite file.

  2. To see structure and other information of this sqlite file , the most efficient way is use SQLITE MANAGER(add on of firefox https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/) add it and then click TOOL .



来源:https://stackoverflow.com/questions/6507395/xcode4-where-to-look-for-sqlite-file-created-by-core-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!