Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Small issue regarding custom document types #30

Closed
colasbd opened this issue Nov 20, 2014 · 3 comments
Closed

Small issue regarding custom document types #30

colasbd opened this issue Nov 20, 2014 · 3 comments

Comments

@colasbd
Copy link

colasbd commented Nov 20, 2014

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 colasbd closed this as completed Nov 20, 2014
@colasbd
Copy link
Author

colasbd commented Nov 20, 2014

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.

@colasbd colasbd reopened this Nov 20, 2014
@mikeabdullah
Copy link
Collaborator

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
Copy link
Author

colasbd commented Nov 24, 2014

Hi !

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants