Mac swift Xib based doc app deletes a doc when I make changes and then save it.

I have a Mac doc based app. I have save methods setup (they sort of work... I'm trying to get them up and running) I'm using NSSecureCoding, with NSObjects in Swift. It has been unusually frustrating.

I have run into something I find wildly difficult to even explain. I can save a new document that has not been saved yet. it loads as expected. but if I make a change to a doc I have already saved, and save that, ny file gets wiped out. my save code is called, and the app wipes all of the data out of the saved file. The file exists, but it's emptied.

it goes from around ~200k in size to 2k in size.

there's no error that I have identified. It just wipes my file. So I have NO idea if it's something I did.

docs are... unhelpful. internet searches... are unhelpful. this is just one of a number of errors I have to figure out, but it is massively complicating everything else.

any ideas welcome.

here is what caused that issue:

when you save the file for the very first time, your identifier is exactly the way you type it in in the text field. here's mine: com.BkTools.blockingDoc

when you save changes to a file, the identifier is lowercased: com.bktools.blockingdoc

I actually test for my type identifier, because I will probably need to have more than one.

So I uses a Switch. and the list of options needs to be exhaustive, so I have a Default: option that returns an empty Data() But that should never get called. under any circumstances. I have a closed loop here. I am saving MY file type, I Am opening MY file type. I have written down MY identifier, so I can Expect MY file identifier.

except. I can't. Somebody transforms my identifier before I get it. which is a cardinal sin. WORSE, they transform my identifier, only SOME of the time. which in my book is far far worse a cardinal sin.

the workaround... when I inevitably run into this problem again and there's no documentation then either:

is to either use all lowercase in the identifier, or to use the convenience method : lowercase() on the string in the switch and just check for the lower case version.

half a day looking for that little gem.

Mac swift Xib based doc app deletes a doc when I make changes and then save it.
 
 
Q