karelia / BSManagedDocument

Brings UIManagedDocument's design to OS X
Other
55 stars 25 forks source link

Small issue regarding custom document types #30

Closed colasbd closed 9 years ago

colasbd commented 9 years ago

Hi Mike !

I think I found a error in your code. I am happy to help you improve your project. Please confirm if you agree. If you don't mind updating the pod, it would be great also !

Your code

- (BOOL)configurePersistentStoreCoordinatorForURL:(NSURL *)storeURL
                                           ofType:(NSString *)fileType
                                            error:(NSError **)error
{
    // On 10.8+, the coordinator whinges but doesn't fail if you leave out NSReadOnlyPersistentStoreOption and the file turns out to be read-only. Supplying a value makes it fail with a (not very helpful) error when the store is read-only
    BOOL readonly = ([self respondsToSelector:@selector(isInViewingMode)] && [self isInViewingMode]);

    NSDictionary *options = @{
                              // For apps linked against 10.9+ and supporting 10.6 still, use the old
                              // style journal. Since the journal lives alongside the persistent store
                              // I figure there's a chance it could be copied from a new Mac to an old one
                              // https://developer.apple.com/library/mac/releasenotes/DataManagement/WhatsNew_CoreData_OSX/index.html
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 && MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_6
                              NSSQLitePragmasOption : @{ @"journal_mode" : @"DELETE" },
#endif

                              NSReadOnlyPersistentStoreOption : @(readonly)
                              };

    return [self configurePersistentStoreCoordinatorForURL:storeURL
                                                    ofType:fileType
                                        modelConfiguration:nil
                                              storeOptions:options
                                                     error:error];
}

It should be

    return [self configurePersistentStoreCoordinatorForURL:storeURL
                                                    ofType:[self persistentStoreTypeForFileType:fileType]
                                        modelConfiguration:nil
                                              storeOptions:options
                                                     error:error];

Thanks for all

colasbd commented 9 years ago

I had an issue because I subclass

configurePersistentStoreCoordinatorForURL: ofType: modelConfiguration:storeOptions:error:

and so, I receive the wrong value for the parameter.

The solution I gave you works and allow the overridden method to get the write type "SQL" instead of my document type.

mikeabdullah commented 9 years ago

Hi, this is deliberate. I'm matching the same behaviour as UIManagedDocument and NSPersistentDocument as far as I'm aware.

The type passed into that method is the document's file type, not the persistent store. If you're overriding configurePersistentStore…, you can still call through to persistentStoreTypeForFileType: there if needed.

colasbd commented 9 years ago

Hi !

Thanks ! My mistake, I implicitly supposed that persistentStoreTypeForFileType: was a private method.