Search code examples
iosswiftarchivingzipzap

Calling ZipZap's updateEntries method causes a crash in Swift


I've been trying to create an archive using the ZipZap library (https://github.com/pixelglow/zipzap) and to be more specific the 8.0 release. The library is consumed in Swift code.

I've read that when calling:

newArchive.updateEntries(archiveItems, error: error)

Requires the "archiveItems" to be NSMutableArray and it is defined as such. At this point I tried creating an archive that contains just one directory so the array looks like:

var archiveItems = NSMutableArray()
archiveItems.addObject(ZZArchiveEntry(directoryName: "\(archiveName)/"))

"newArchive" is created the following way:

var newArchive = ZZArchive(URL: NSURL(fileURLWithPath: archivePath), error: error)

The error I see is: EXC_BREAKPOINT(code=1, subcode=0x1001bc998)

And I've also seen: EXC_BREAKPOINT(code=1, subcode=0x100100998)

In case I do not call the updateEntries method the code does not crash. So my assumption is that the crash happens inside this method.


Solution

  • At the end it was me not reading the spec as it is written in the example on GitHub.

    After a help from Glen Low (pixelglow) the issue was that I am actually trying to create a new file without sending an option to create the file in case it does not exist.

    So a massive thanks goes to pixelglow for his help and the great library!

    The proper way to call the init when you need to create the file is:

    var newArchive = ZZArchive(URL: NSURL(fileURLWithPath: archivePath), options: [ZZOpenOptionsCreateIfMissingKey: true], error: &archiveError)