I am trying to zip and unzip some data with password protection in swift. I found this QUESTION, but I'm unaware about Obj-C. I am seeking a help to zip some data with password protection in swift.
Asked
Active
Viewed 3,133 times
1 Answers
1
You can use any Objective-C zipping class (such as ZipArchive). When adding it to your Swift project, Xcode will ask whether it shall set up a bridging header for you (in case you don't have one already). Afterwards just add an import statement for the zipping class' header file in the bridging header. Compile once, and you should be able to call that Objective-C class from your Swift code.

hennes
- 9,147
- 4
- 43
- 63
-
I didn't find any good zipping class that work on cocoa pods. – Mohammed Janish Sep 13 '15 at 10:50
-
1@MohammedJanish ZipArchive is available through Cocoa Pods ([link](https://cocoapods.org/?q=ziparchive)). – hennes Sep 13 '15 at 11:12
-
from the reference from this [question](http://stackoverflow.com/questions/7525180/how-to-zip-file-using-ziparchive-library-in-iphone)I followed the steps. But, the return value when zipping is false. Here is my code – Mohammed Janish Sep 14 '15 at 06:04
-
`var zipdest = (documentsPath as String).stringByAppendingPathComponent("MyMessage.zip") var zip: ZipArchive = ZipArchive() var ret = zip.CreateZipFile2(zipdest, password: sessionKey, append: true) var xmldest = (documentsPath as String).stringByAppendingPathComponent("Message.txt") soaprequest.xmlString.writeToFile(xmldest, atomically: true, encoding: NSUTF8StringEncoding) ret = zip.addFileToZip(xmldest, newname: "test.xml")` – Mohammed Janish Sep 14 '15 at 06:06
-
@MohammedJanish You should open a new question for this since this one is already answered. Also the scope of the present question is more broad than your new problem. Opening a new question will get you more attention from other users. – hennes Sep 14 '15 at 06:35
-
rewriting the code with no changes made gave me the result. I don't know what was the problem, but it's working fine now. I'll get another question if I find more roadblocks which need reference. Thanks. – Mohammed Janish Sep 14 '15 at 06:54