Core Data | Third Edition | Chapter 6 THREADING ERROR in Custom Migration

Hello, I have been working my way through the Core Data by Tutorials third edition iOS 10 and Swift 3 edition, and I found some issues with the source code in the book, as well as the final version source code that is provided with the book.

I have to finish the book and will review the chapter and see if there is a solution to this error. It seems minor, but I have not investigated it. If you have had similar issues or found a solution please post any information below.
Chapter 6 Custom Migration
Section where Threading Error was thrown:
// File: DataMigrationManager.swift
//line 99
func performMigration() {
if !currentModel.isVersion4 {
fatalError(“Can only handle migrations to version 4!”)//Thread 1: Fatal error: Can only handle migrations to version 4!
}

Threading Error:
2018-01-18 14:41:33.670219-0800 UnCloudNotes[1368:29638] [MC] Lazy loading NSBundle MobileCoreServices.framework
2018-01-18 14:41:33.671211-0800 UnCloudNotes[1368:29638] [MC] Loaded MobileCoreServices.framework
2018-01-18 14:41:33.695435-0800 UnCloudNotes[1368:29638] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/rae/Library/Developer/CoreSimulator/Devices/95FDB2E4-88C2-4EA4-BC88-3A988514EAA6/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
(lldb)

@casademora Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi. Would you mind posting the actual stack trace you encountered? I’ll have a look at it this evening. Thanks :slight_smile:

So, I don’t believe this is a threading error explicitly. It does seem that you’ve somehow not detected the current supported version properly and the core data version detection code (!currentModel.isVersion4) is passing, thus triggering the explicit failure defined by the fatalError call.

Can you check to make sure that your core data file is the correct version from which you expect to be migrating at this point?

This error occurs if you don’t have any data stored yet. The test for whether you have version4 fails if you don’t even have a database at all.

performMigration() itself checks if storeModel is nil, and skips trying the migration if so. You just need a test of storeModel before the “fatal error” test, something like this:

guard let storeModel = self.storeModel else { return }

guard currentModel.isVersion4 else {
  fatalError("Can only handle migrations to version 4!")
}

This topic was automatically closed after 166 days. New replies are no longer allowed.