0

I have a zip file inside my Xcode project which I added as bundle resource: enter image description here

The purpose of this zip is being unzipped during tests and check the inner json files.

It has worked like a charm til now. I had to update the json files regardless a new feature so I replaced the zip with a new one.

The problem now is that when I unzip the file using 'Zip', '1.1.0' library I got a redundant level of deepness in the simulator documents directory: Expected json location:

/Library/Developer/CoreSimulator/Devices/851211C4-7115-468F-8BE3-00CB08B154C5/data/Containers/Data/.../Documents/decrypted_backup_with_groups/contacts.json

Real location after unzip:

/Library/Developer/CoreSimulator/Devices/851211C4-7115-468F-8BE3-00CB08B154C5/data/Containers/Data/.../Documents/decrypted_backup_with_groups/decrypted_backup_with_groups/contacts.json

Code:

let zippedFiles = try Zip.quickUnzipFile(path)

                let contactsFileJson = NSString(string: "\(zippedFiles.path)/contacts.json").expandingTildeInPath
                let contactsData = try Data(contentsOf: URL(fileURLWithPath: contactsFileJson))
                let backupContacts = try JSONDecoder().decode(ContactsBackupDTO.self, from: contactsData)

Error:

Error Domain=NSCocoaErrorDomain Code=260 "The file “contacts.json” couldn’t be opened because there is no such file."

Andoni Da Silva
  • 1,161
  • 15
  • 31
  • What's the value of `zippedFiles`? `zippedFiles` being an `URL`, why not append to it `contacts.json` using the `URL` available methods instead of constructing like String? Could the change be because of `quickUnzipFile()`? Was it the same method your were using previously? The same lib version? – Larme Oct 20 '21 at 06:59
  • zippedFiles is a URL: /Library/Developer/CoreSimulator/Devices/851211C4-7115-468F-8BE3-00CB08B154C5/data/Containers/Data/.../Documents/decrypted_backup_with_groups/decrypted_backup_with_groups. Yes, indeed, I did not change the code nor the lib version, just the zip file. Thanks – Andoni Da Silva Oct 20 '21 at 07:21
  • Does the same thing happen now, if you put your original zip file back? It looks like when you re-zipped your file(s), you compressed the folder structure along with the file(s). – DonMag Oct 20 '21 at 13:57
  • I found a solution in this post: [https://stackoverflow.com/questions/10924236/mac-zip-compress-without-macosx-folde](https://stackoverflow.com/questions/10924236/mac-zip-compress-without-macosx-folder). – Andoni Da Silva Oct 20 '21 at 13:59

0 Answers0