iOS 上 swift3 的原生 zlib 充气/放气 [英] native zlib inflate/deflate for swift3 on iOS

查看:18
本文介绍了iOS 上 swift3 的原生 zlib 充气/放气的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够膨胀/收缩 Swift3 数据结构.我找到了 GzipSwift,但不清楚我如何将其提供给我的 iOS 应用程序.我尝试过的幼稚的事情包括:

I'd like to be able to inflate/deflate Swift3 Data structs. I found GzipSwift, but it's not clear how I make that available to my iOS app. The naive things I've tried include:

  1. Data+Gzip.swift 文件复制到我自己的项目中.然后,这会抱怨所述文件顶部的 import zlib.我认为这与相同来源的 zlib 目录中的模块映射文件有关.但我不确定在我自己的项目中如何或如何重新创建这些.

  1. Copying the Data+Gzip.swift file into my own project. This then complains about the import zlib at the top of said file. I think that has something to do the with the modulemap files in the zlib directory of the same sources. But I'm not sure what or how to recreate those in my own project.

从github克隆存储库,打开XCode并内置(基本上按下运行按钮).然后尝试将其作为链接库或框架添加到我自己的项目中.我很确定只是选择存储库的顶级目录不是我想要做的,但我不知道还能尝试什么.

Cloned the repository from github, opened XCode and built in (pressed the run button basically). Then tried to add that as a linked library or framework to my own project. I'm pretty sure just selecting the top level directory of the repository is not what I want to do, but I didn't know what else to try.

我在那里找到了一些其他代码,但它似乎过时并且与 Swift2 相关.

I've found some other code out there, but it seems dated and relative to Swift2.

推荐答案

我最近不得不将那个确切的库和文件添加到我的项目中,经过大量故障排除后终于让它工作了,所以让我带你完成脚步!

I just recently had to add that exact library and file to my project, and after a lot of troubleshooting finally got it working, so let me walk you through the steps!

好的

1) 转到 finder 中项目的顶级目录,然后创建一个名为 Swiftzlib 的新文件夹,或者您想要导入的模块的名称.(我们要做的是将 zlib 库添加为模块,因此可以将其视为导入 Foundation 或其他此类模块).澄清一下,这个 Swiftzlib 目录最终将作为包含 *.xcodeproj*.xcworkspace 文件的同一目录的子目录.

1) Go to the top level directory of your project in finder, and create a new folder called Swiftzlib or whatever you want the name of the module that you will be importing to be. (What we will do is add the zlib library as a module, so think of it as importing Foundation or some such other module). To clarify, this Swiftzlib directory will end up as a child directory of the same directory that contains your *.xcodeproj and *.xcworkspace files.

2) 在您创建的文件夹中,创建两个文件.

2) Inside the folder you created, make two files.

  • include.h
  • module.modulemap

3) 在您的 include.h 文件中,输入以下内容:

3) In your include.h file, enter the following:

#include<zlib.h>

4) 在您的 module.modulemap 文件中,输入以下内容:

4) In your module.modulemap file, enter the following:

module Swiftzlib [system] {
    header "include.h"
    export *
}

其中 Swiftzlib 与您创建的文件夹的名称相同.

Where Swiftzlib is the same as the name of the folder that you created.

5) 打开您的 Xcode 项目,然后选择您的目标

5) Open your Xcode project, and select your target

  • 5a) 在 Build Phases -> Link Binary with Libraries 中,添加 libz.tbd
  • 5b) 在 Build Settings -> Swift Compiler - Search Paths 中,将 $(PROJECT_DIR)/Swiftzlib 以非递归方式添加到导入路径
  • 5c) 在 Build Settings -> Other Linker Flags 中,添加 -lz 作为标志
  • 5a) In Build Phases -> Link Binary with Libraries, add libz.tbd
  • 5b) In Build Settings -> Swift Compiler - Search Paths, add $(PROJECT_DIR)/Swiftzlib non-recursively to the import paths
  • 5c) In Build Settings -> Other Linker Flags, add -lz as a flag

6) 在 Xcode 中选择你的项目(可能不是必需的,但我已经在我的项目中完成了它并且它有效)

6) Select your project in Xcode (may not be necessary, but I've done it in my project and it works)

  • 6a) 在 Build Settings -> Swift Compiler - Search Paths 中,将 $(PROJECT_DIR)/Swiftzlib 以非递归方式添加到导入路径
  • 6a) In Build Settings -> Swift Compiler - Search Paths, add $(PROJECT_DIR)/Swiftzlib non-recursively to the import paths

7) 在Data+Gzip.swfit中,在文件顶部添加import Swiftzlib

7) In Data+Gzip.swfit, add import Swiftzlib to the top of the file

8) 清理、构建和运行!

这篇关于iOS 上 swift3 的原生 zlib 充气/放气的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆