2

Hello im getting an error if i implement SwiftUI into my app which is based on storyboard at the moment. I made a SwiftUI file and i can also display my SwiftUI view within my app. However if i try to make a preview within XCode of my SwiftUI file i get the following error:

Showing All Messages
CompileAssetCatalog /Users/n0name/Library/Developer/Xcode/DerivedData/MediaApp-auxosshpupveyzcyqpenlftpfxti/Build/Intermediates.noindex/Previews/MediaApp/Products/Debug-iphonesimulator/MediaApp.app /Users/n0name/Desktop/sevdaDev/MediaApp/MediaApp/MediaApp/Assets.xcassets (in target 'MediaApp' from project 'MediaApp')
    cd /Users/n0name/Desktop/sevdaDev/MediaApp/MediaApp
    /Applications/Xcode.app/Contents/Developer/usr/bin/actool --output-format human-readable-text --notices --warnings --export-dependency-info /Users/n0name/Library/Developer/Xcode/DerivedData/MediaApp-auxosshpupveyzcyqpenlftpfxti/Build/Intermediates.noindex/Previews/MediaApp/Intermediates.noindex/MediaApp.build/Debug-iphonesimulator/MediaApp.build/assetcatalog_dependencies --output-partial-info-plist /Users/n0name/Library/Developer/Xcode/DerivedData/MediaApp-auxosshpupveyzcyqpenlftpfxti/Build/Intermediates.noindex/Previews/MediaApp/Intermediates.noindex/MediaApp.build/Debug-iphonesimulator/MediaApp.build/assetcatalog_generated_info.plist --app-icon AppIcon --compress-pngs --enable-on-demand-resources YES --development-region en --target-device iphone --target-device ipad --minimum-deployment-target 13.4 --platform iphonesimulator --compile /Users/n0name/Library/Developer/Xcode/DerivedData/MediaApp-auxosshpupveyzcyqpenlftpfxti/Build/Intermediates.noindex/Previews/MediaApp/Products/Debug-iphonesimulator/MediaApp.app /Users/n0name/Desktop/sevdaDev/MediaApp/MediaApp/MediaApp/Assets.xcassets

2021-06-17 15:51:57.997 ibtoold[28465:1115997] DEBUG: Added to environment: {
    TMPDIR = "/var/folders/5v/p26rjcc50bxcjkcj8h4z2tq40000gn/T/C9D47C23-18B9-48A8-BE11-80115C363851";
}
CoreData: error:  API Misuse: Attempt to serialize store access on non-owning coordinator (PSC = 0x7fe52157bef0, store PSC = 0x0)
CoreData: error:  API Misuse: Attempt to serialize store access on non-owning coordinator (PSC = 0x7fe52157bef0, store PSC = 0x0)
2021-06-17 15:52:09.204 IBCocoaTouchImageCatalogTool[28466:1116234] *** Assertion failure in -[CoreThemeDocument metadatumForKey:], CoreThemeDocument.m:8011
2021-06-17 15:52:09.205 IBCocoaTouchImageCatalogTool[28466:1116234] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[CoreThemeDocument metadatumForKey] expects exactly one persistent store, but got 0.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff20422fba __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007fff20193ff5 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff20422de3 +[NSException raise:format:] + 0
    3   Foundation                          0x00007fff207748e7 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
    4   CoreThemeDefinition                 0x00007fff4cc7b7b5 -[CoreThemeDocument metadatumForKey:] + 205
    5   CoreThemeDefinition                 0x00007fff4cc7ca4b -[CoreThemeDocument allowsExtendedRangePixelFormats] + 29
    6   CoreThemeDefinition                 0x00007fff4cca1c1e -[TDSimpleArtworkRenditionSpec createCSIRepresentationWithCompression:colorSpaceID:document:] + 5410
    7   CoreThemeDefinition                 0x00007fff4ccac5f0 __34-[TDRenditionsDistiller _distill:]_block_invoke + 120
    8   CoreData                            0x00007fff250d323a developerSubmittedBlockToNSManagedObjectContextPerform + 154
    9   libdispatch.dylib                   0x00007fff201078df _dispatch_client_callout + 8
    10  libdispatch.dylib                   0x00007fff2010de15 _dispatch_lane_serial_drain + 715
    11  libdispatch.dylib                   0x00007fff2010e98c _dispatch_lane_invoke + 400
    12  libdispatch.dylib                   0x00007fff20118f81 _dispatch_workloop_worker_thread + 772
    13  libsystem_pthread.dylib             0x00007fff6034045d _pthread_wqthread + 314
    14  libsystem_pthread.dylib             0x00007fff6033f42f start_wqthread + 15
)
libc++abi: terminating with uncaught exception of type NSException

The thing is i dont know why i get this error. If i run my app on the simulator i dont see any error like this. This error does NOT occur in the simulator, humh?

The above code occurs within the step "Showing All Messages CompileAssetCatalog" in the log. Because the error has been occurred in this step i thought it could have some relation to the assets (images and vectors graphics) which i am using. I therefore deleted my whole asset files except my "AppIcon" and tried to run the preview within XCode again and it did work!!. However i dont know why my assets has to do with "NSObjectManager" or "PersistentContainer" "CoreData" and other Thread problems where im redirected if i search for the same error. One of the posts is for example this: FetchedResultsController Swift 3 API Misuse: Attempt to serialize store access on non-owning coordinator

But i dont use complex things like "Persistent Container". I only use some keys in my userDefaults which are being saved there and also being retrieved. I also use Firebase. I dont understand much about threads and concurrency to be honest. So can someone explain me why exactly this error occurs and why i get really strange behaviour like this? Why do my simple image and vector assets cause problems like this????

I asked one of my colleagues who is also working on same project she gets the same result if she tries to open the preview of a new created SwiftUI view.

esen
  • 90
  • 5
  • 1
    What is `CoreThemeDocument`? It comes up a few times in the error messages, and it looks like it's relevant to the problem. – Tom Harrington Jun 17 '21 at 18:21
  • Hello @TomHarrington i think i could identify the exact problem. I have found a JSON file from lottie within my Assets.xcassets and i removed it. So after restarting XCode and my macintosh it seems that the error is gone. The swiftUI preview within XCode works now as expected. However i dont have any clue why this has caused an error like this. I can only imagine that the JSON file was being processed be a thread too long which caused the upcoming error. Hope that this solution helps someone with the same error. I also hope that the error is not gone temporarily. BTW thanks for your comment =) – esen Jun 17 '21 at 18:59
  • What 'CoreThemeDocument' does mean... i really dont know. I also searched for this with google however could not find anything related to it. Also searched for 'metadatumForKey' because im not using any word like this in my source code. I have tried to find those words within the json file what i deleted but could not find anything. So seems to be a really strange thing. – esen Jun 17 '21 at 19:08

1 Answers1

2

When I first read the question I didn't realize that this was a compiler error-- I thought it was happening when the app was running.

When the compiler has an error like this, indicating a crash, it's a bug in the compiler. Always. That should never happen. From your comments it sounds like your JSON file was triggering this bug. I don't know if it's something weird about that JSON file or if it's that Xcode doesn't like having JSON in an asset catalog. Either way though, it's an Xcode bug, because in the worst case Xcode should have told you to not put a JSON file there instead of doing this.

It's good to hear that you found a workaround. It's not something you can actually fix, but if your workaround does what you need then that's close enough. Apple could fix it though, so I recommend visiting https://feedbackassistant.apple.com and filing a bug about this.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
  • 1
    Thank you first of all that you took your valuable time to read my post and also tried to figure out what the problem is. I really appreciate it that user like you are contributing to stackoverflow. As i can see you are an expert when it comes to CoreData and complex situations like this. In the end people like you encourage me that i should stick on swift and not give it up. As you suggested i recently submitted a ticket to apple regarding this error. I am also happy we could find a solution for this problem! =) – esen Jun 18 '21 at 14:18