Is there a practical way to compress NSData?

后端 未结 7 1928
感情败类
感情败类 2020-12-14 11:40

I haven\'t seen any documentation on the topic, but that doesn\'t mean it doesn\'t exist.

7条回答
  •  猫巷女王i
    2020-12-14 12:05

    In iOS 13 and macOS 10.15 or newer you can use the new compressed method of NSData:

    let compressedData = try? NSData(data: data).compressed(using: .zlib)
    

    Unfortunately this method hasn't been ported to Swift's native Data class, but NSData can be simply casted to Data by adding as Data after the above code line.

提交回复
热议问题