Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Running first time ...moody Failed to create file at ModelVersionType.swift #5

Open
Sun3 opened this issue Jan 16, 2016 · 2 comments
Open

Comments

@Sun3
Copy link

Sun3 commented Jan 16, 2016

Running first time I receive crash ...moody Failed to create file. This happens in the ModelVersionType.swift in the extension NSManagedObjectContext {...} It crashes on line let psc = NSPersistentStoreCoordinator(...)

Any ideas? I have made all of the changes for the CloudKit setup.
Thank you.

CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/name/Library/Developer/CoreSimulator/Devices/50A111d9-B60C-49D0-d037-CAD21D8G96CC/data/Containers/Data/Application/3DE20E67-C970-4A56-A138-538D8F0420A6/Documents/YnBsaXN0MDDUAQIDBAUGCQpYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hvdmGyVCR0b9ASAAGGoKIHCFUkbnVbbC8QFBQ3L/RDZAr0ISZbweTAix7l2EpRXxAPTlNLZXllZEFyY2vpdmCy0RsMEHJvb3SAAQgRGiMtMjc6TFdpbHEAAAAAAAABAQAAAAAAAAANAAAAAAAAAAAAAAAAAAAAcw==.moody options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=512 "The file couldn’t be saved." UserInfo={reason=Failed to create file; code = 2} with userInfo dictionary {
    reason = "Failed to create file; code = 2";
}
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=512 "The file couldn’t be saved." UserInfo={reason=Failed to create file; code = 2}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.1.101.15/src/swift/stdlib/public/core/ErrorType.swift, line 50
extension NSManagedObjectContext {
    public convenience init<Version: ModelVersionType>(concurrencyType: NSManagedObjectContextConcurrencyType, modelVersion: Version, storeURL: NSURL, progress: NSProgress? = nil) {
        if let storeVersion = Version(storeURL: storeURL) where storeVersion != modelVersion {
            migrateStoreFromURL(storeURL, toURL: storeURL, targetVersion: modelVersion, deleteSource: true, progress: progress)
        }

        let psc = NSPersistentStoreCoordinator(managedObjectModel: modelVersion.managedObjectModel())   // CRASH HAPPENS HERE...

        try! psc.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: nil)
        self.init(concurrencyType: concurrencyType)
        persistentStoreCoordinator = psc
    }
}
@johnodowd
Copy link

Hi Sun3
I have come across this error when setting up my project as well. The issue it the ubiquityToken method in the MoodyStack.swift file. This method returns a string which has a forward slash in the string. As a quick workaround I changed the following line from

return NSKeyedArchiver.archivedDataWithRootObject(token).base64EncodedStringWithOptions(NSDataBase64EncodingOptions())

to

return NSKeyedArchiver.archivedDataWithRootObject(token).base64EncodedStringWithOptions(NSDataBase64EncodingOptions()).stringByReplacingOccurrencesOfString("/", withString:"")

I don't know if this will interfere with the migration and versioning code, as I have only started to look over the code, so you should test this if you need the code for an app

@Sun3
Copy link
Author

Sun3 commented Jan 25, 2016

@johnodowd That worked great. I appreciate the help, thank you.

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

No branches or pull requests

2 participants