本文介绍了适用于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目录中的modulemap文件有关.但是我不确定在我自己的项目中用什么或如何重新创建它们.

  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)在构建阶段->使用库链接二进制文件"中,添加libz.tbd
  • 5b)在构建设置"->"Swift编译器-搜索路径"中,非递归地将$(PROJECT_DIR)/Swiftzlib添加到导入路径
  • 5c)在构建设置"->其他链接器标志"中,添加-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)在构建设置"->"Swift编译器-搜索路径"中,非递归地将$(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充气/放气的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 19:26