Core Data apps no longer working after update to iOS27

I have two apps that both use Core Data. Since updating to XCode 27.1 and iOS 27 one works and one does not. Both apps have AppDelegates, SceneDelegates and CoreDataStacks that are the same, except for data entity names, etc.

With App A, this works:

extension StartViewController {

func importJSONPlaceSeedDataIfNeeded() {
    
    let fetchRequest: NSFetchRequest<Places> = Places.fetchRequest()
    let count = try? coreDataStack.context.count(for: fetchRequest)
    
    guard let placeCount = count,
          placeCount == 0 else {
        return
    }
    
    importJSONPlaceData()
}

With App B, this does not work:

extension StartViewController {

func importBirdsJSONSeedDataIfNeeded() {
    
    let fetchRequest: NSFetchRequest<Birds> = Birds.fetchRequest()
    let count = try? coreDataStack.context.count(for: fetchRequest)
    
    guard let birdCount = count,
        birdCount == 0 else {
            return
    }
    
    importBirdsJSONData()
}

I get the error: Kafue_Birds/StartViewController.swift:77: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

The line that throws the error is: 

 let count = try? coreDataStack.context.count(for: fetchRequest)


 Any suggestions?

The error indicates a Swift force unwrap failure. That is, when running coreDataStack.context.count(for: fetchRequest), something (most likely coreDataStack or coreDataStack.context) not supposed to be nil is nil, but your code example doesn't convey enough info to tell what exactly it is.

Depending on how you initialize your Core Data stack, it can be that the stack or the context isn't ready yet when you do the import. You can start with identifying what shouldn't be nil is nil, and then trace along your code path to figure out why.

Sharing a code example that reproduces the issue for folks to take a closer look will help as well, if that is convenient to you.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.