yepher / CoreDataUtility

An OSX application that simplifies development and debugging of CoreData enabled applications.
519 stars 49 forks source link

Xcode 6 and iOS 8 support #29

Closed ostatnicky closed 9 years ago

ostatnicky commented 9 years ago

I don't see Managed Object Models generated from Xcode 6.

yepher commented 9 years ago

Thanks for the report. I will have a look.

After a little bit of investigation it looks like XCode has moved where the iOS Simulator files are stored. Now the .app and presistance files are stored here:

~/Library/Developer/CoreSimulator/Devices/C7FA676B-F325-4D4B-8066-5D9D8D752E68/data/Containers/Bundle/Application/176630E0-B32E-49CB-ADFC-EE5B99F20E98/MyFile.app/
~/Library/Developer/CoreSimulator/Devices/C7FA676B-F325-4D4B-8066-5D9D8D752E68/data/Containers/Data/Application/E70E7E26-7FC5-4703-A8E8-827856CF0B38/Documents/MyFile.sqlite

Until there is a code fix to automatically find the files you could open the "*.app" and persistence files manually from the "file" tab or pass the file names from the command line.

ostatnicky commented 9 years ago

Thanks for support! I found that path was changed too...

yepher commented 9 years ago

While looking into this I found that the applications data path changes each time the app is run.

Unless someone else has a better solution I think for the "project file" to work it will need to remember the persistence file name and search for it in the simulators directory structure.

Example:

This is original path to persistence file:

~/Library/Developer/CoreSimulator/Devices/C7FA676B-F325-4D4B-8066-5D9D8D752E68/data/Containers/Data/Application/E70E7E26-7FC5-4703-A8E8-827856CF0B38/Documents/MyFile.sqlite

and this is the path when the app is run again:

~/Library/Developer/CoreSimulator/Devices/C7FA676B-F325-4D4B-8066-5D9D8D752E68/data/Containers/Data/Application/A7B0E435-007A-4D9E-ABAC-B853EAB93526/Documents/MyFile.sqlite

So UUID changed from: "E70E7E26-7FC5-4703-A8E8-827856CF0B38" to "A7B0E435-007A-4D9E-ABAC-B853EAB93526".

yepher commented 9 years ago

Here is another (better?) work around for the problem.

Add this code to your iOS application:

#if TARGET_IPHONE_SIMULATOR
+ (void) createCoreDataDebugProjectWithType: (NSNumber*) storeFormat storeUrl:(NSString*) storeURL modelFilePath:(NSString*) modelFilePath {
    NSDictionary* project = @{
                              @"storeFilePath": storeURL,
                              @"storeFormat" : storeFormat,
                              @"modelFilePath": modelFilePath,
                              @"v" : @(1)
                              };

    NSString* projectFile = [NSString stringWithFormat:@"/tmp/%@.cdp", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey]];

    [project writeToFile:projectFile atomically:YES];

}
#endif

Now call that code where you initialize your CoreData persistent store. Something like this:

#if TARGET_IPHONE_SIMULATOR
    // @(1) is NSSQLiteStoreType
    [self createCoreDataDebugProjectWithType:@(1) storeUrl:[storeURL absoluteString] modelFilePath:[modelUrl absoluteString]];
#endif

Now you can just ope the /tmp/YourAppName.cdp file and it will open CoreDataUtility with your app's data loaded.

This is CoreDataUtilities storage types:

typedef NS_ENUM(NSInteger, MFL_StoreTypes) {
    MFL_SQLiteStoreType = 1,
    MFL_XMLStoreType = 2,
    MFL_BinaryStoreType = 3,
    MFL_InMemoryStoreType = 4,
};
yepher commented 9 years ago

I think this is a much better solution for folks so I am going to call this a fixed for now. If I can figure out a way to deterministically find the simulators data path I will come back to this.

Added instructions the project README.md.

felipe-nrscorps commented 9 years ago

Thanks!!!