0

A long time ago I made a simple CoreData, document-based app and used Xcode to make a file type/extension to go along with it. Now, I'm following the WWDC videos from last year to try to update to SwiftData. The instructions show that the Exported Type Identifier in the target's info should "conform" to com.apple.package. I didn't include that conformance in the original CoreData project. When I try to build the partially-remade project for initial testing, it immediately crashes with: "_SwiftData_SwiftUI/Documents.swift:282: Fatal error: The document type is *** which does not conform to com.apple.package. This initializer expects the document type to be a package."

If I just change the file extension in the Exported Type Identifier (and the UTType class extension code) to anything other than the original extension from years ago, the app will load, so the rest of the type setup must be correct. My guess was that the issue is macOS recognizes the file type from my older program, and knows it didn't used to conform to com.apple.package, so it won't allow the new SwiftData version to run, since conformance is required.

I tried opening the original CoreData project in Xcode, adding com.apple.package to "conforms to" in the Exported Type Identifier and running it, and confirmed I can still open my old files. I hoped that would "update" the system that it's now conforming. However, going back to the SwiftData project, it still won't load, and gives the same fatal error.

I then tried running my SwiftData project on another computer that has never run the CoreData version, and it built just fine - which seems to confirm the issue is my laptop's prior knowledge of that file type.

I tried asking this question on StackOverflow, but there's debate about whether it's solvable by programming or if it can only be solved at the OS level, so the question was closed. Is there a way to make macOS update the file type (either through programming or an OS setting) so it knows conformance to com.apple.package has been added? Or else, can I make macOS forget it's ever seen that file type/extension, so when the program is opened next time it registers the type with the new conformance?

2
  • It's probably something in the LaunchServices DB.
    – benwiggy
    Commented May 2 at 20:42
  • Which version of macOS? Commented May 3 at 16:20

1 Answer 1

2

I am not sure if my past problem was exactly the same as yours. What I did to make macOS forget was to enter the following command.

% # Do the following with and without sudo
% /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
% # Next: Relaunch the Finder

For the preposes of documentation, here is the output from lsregister -h on Ventura.

lsregister: [OPTIONS] [ <path>... ]
                      [ -apps <domain>[,domain]... ]
                      [ -libs <domain>[,domain]... ]
                      [ -all  <domain>[,domain]... ]

Paths are searched for applications to register with the Launch Service database.
Valid domains are "system", "local", "network" and "user". Domains can also
be specified using only the first letter.

  -delete       Delete the Launch Services database file. You must then reboot!
  -kill         Reset the Launch Services database before doing anything else
  -seed         If database isn't seeded, scan default locations for applications and libraries to register
  -lint         Print information about plist errors while registering bundles
  -lazy n       Sleep for n seconds before registering/scanning
  -r            Recursive directory scan, do not recurse into packages or invisible directories
  -R            Recursive directory scan, descending into packages and invisible directories
  -f            force-update registration even if mod date is unchanged
  -u            unregister instead of register
  -v            Display progress information
  -gc           Garbage collect old data and compact the database
  -dump [table] Display full database contents after registration
  -h            Display this help

References

1
  • I had just run across something similar after the hint from @benwiggy. It looks like this works - Xcode at least ran the project without the immediate fatal crash (though it's still a mostly blank program, just loading the SwiftData model and a basic layout). Thanks! I'll just add an update once I know if I can still open the old CoreData files, or update the CoreData version correctly to use the package conformance, so my old documents don't get trashed. Commented May 5 at 4:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .