App Won't Recognize its Files

I've been out ot the game for 6-9 months, now wanting to get back at it. Earlier, had a Time Machine backup, but not since. First thing I tried was to upgrade everything to current. Tried to install High Sierra. Total disaster. Ended up going to Apple Store, buying a new disk, booting off their network, doing a complete backup. They wiped my MacBookPro and installed High Sierra. I have restored XCode, development files, and data files. I was able to compile and launch the recompiled Mac App (currently in App Store) from XCode. But the app does not recognize any of it data files. These each consist of a package with a CoreData file plus a folder of media files. The error dialog is as follows:


"The document “NewOSTest” could not be opened. The file isn’t in the correct format. The file might be corrupted, truncated, or in an unexpected format."


I get that on all my data files. Ok, now what?

Replies

I get that on all my data files. Ok, now what?

It sounds you’ve created a document-based app using

NSDocument
. Your next step is to determine whether:
  • AppKit is not able to map your file to your

    NSDocument
    subclass
  • Your

    NSDocument
    subclass is unable to read the file

To do this, set a breakpoint in your document reading code and see if a) that gets called, and b) if it fails with an error.

NSDocument
has a bunch of different document read methods you could have overridden, so you’ll have look for the exact method. It’s likely to be one of the methods that starts with
readFrom
.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

The problem appears to be in CoreData. I had stored one transformable object for an NSIndexPath in my "Status" persistant object. This was not a problem in the past. I see that NSIndexPath conforms to NSSecureCoding, but not NSCoding. Is this a recent change?

Hi,


I believe an accepted answer was found to a similar question here :


https://forums.developer.apple.com/thread/84588

That certainly looks relevant and is consistent with my error messages. Unfortunately, that fix didn't work, possibly because I'm using a sql file, not binary. I checked to make sure it was using the specified options.

The problem appears to be in CoreData.

OK. Given that I’ve moved your thread over to App Framworks > Core Data, where you’re more likely to connect up with folks with Core Data expertise.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Did you try the version where you add the problematic class (NSIndexPath) to your passed in value for NSBinaryStoreSecureDecodingClasses?

The secure decoding options should be getting applied to wherever CoreData does transformation using encoding/decoding, not just the flatfile binary format.

.Yes, but it appears that I'm storing as NSSQLiteStoreType, not NSBinaryStoreType. Probably should have used the latter. Is that going to make a difference?


It looks to me like the SQLite store is the only one that allows partial access from the disk. (At least that's what's stated for iOS, but we are on Mac). Our app is a presentation system for making educational/training movies created by screen capture. The CoreData store can contain an entire semester's worth of raw presentations in one database. We do outboard all media files in a separate folder in the package and access them via Managed media objects.


Addendum:

Apparently, this is actually working, well, to an extent. By repeatedly trying to open a document and adding the currently offending class to the list, it eventually opened. But this means that I have to go through every managed object in entire object model and add all the transformed classes to the list. Not ideal.

So far, I'm managed to get it to accept everything overtly used as a transformable property. However, I an getting complaints about NSPDFImageRep, which I don't explicitly use -- just NSImage. I added NSPDFImageRep to the list, but it didn't help.


NSUnderlyingException=value for key 'NS.objects' was of unexpected class 'NSPDFImageRep'. Allowed classes are '{(

NSBitmapImageRep,

NSCGImageSnapshotRep,

NSCachedImageRep,

NSArray,

NSNumber

)}

to the Here's what I've been able to ascertain so far. The problem is in a small database maintained at the application level. If this database does not exist in the ApplicationSupport area, it will recreate it from resources, and on first launch it works just fine because the model is already available. For subsequent launches, it does not work because it won't read from the database. During a normal run, other items may be stored in this database. There is also a tool provided for the user to create and add more items. Some items use QuartzComposer files. Others use static images with a settable hotSpot and optional animations. Some of these NSImages use a PDF (NSPDFImageRef). Unfortunately, NSPDFImageRef does not conform to NSSecureCoding. So, adding NSPDFImageRef to the NSBinaryStoreSecureDecodingClasses list does not work. As a result, an exception is thrown and this database does not get read-in and used. This makes a HighSierra update to the app not usable with existing data files.


Any suggestions as to what to try next?

You've been going through adding to the secure decoding list so far.

You should be able to add NSPDFImageRef to a set and pass it as NSBinaryStoreInsecureDecodingCompatibilityOption in the same way that you've been doing for the secure classes.

Thanks. Passing it as a set did not work, but "NSBinaryStoreInsecureDecodingCompatibilityOption : @YES" did work. I still have the other offenders as a NSSet with NSBinaryStoreSecureDecodingClasses. Not sure if I should remove them.


It would be nice if Apple, Inc. would provide some decent documentation on this stuff before just springing it on us. :-(