技术教程iOS Developer程序员

你应该懂得protobuf

2017-06-23  本文已影响68人  百草纪

本文记录配置环境过程,不介绍使用过程

protobuf-swift版的安装

  • 这是官方给出的环境配置过程,还有一篇官方专门针对objeswift的配置教程
  • 不要马上就敲啊,待我一步步解说其中的坑点

1.ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.brew install automake

3.brew install libtool

4.brew install protobuf

5.git clone git@github.com:alexeyxo/protobuf-swift.git

6../scripts/build.sh

Add ./src/ProtocolBuffers/ProtocolBuffers.xcodeproj in your project.

前四步是没有问题的

  • 对应的解决方法
  • 一:git clone https://github.com/alexeyxo/protobuf-swift.git
  • 如果是OC开发,就把其中的swift改成objc,下同
  • 二:直接手动下载下来,在放在这个位置,记得要把-master删掉
  • 跟着博客走是下面这样
  • cd ~/protobuf-swift
  • ./autogen.sh
  • ./configure
  • 进行./configure可能会报错,不过别着急,先分析错误信息
configure: error: 

ERROR: protobuf headers are required.
You must either install protobuf from google,
or if you have it installed in a custom location
you must add '-Iincludedir' to CXXFLAGS
and '-Llibdir' to LDFLAGS.
If you did not specify a prefix when installing
protobuf, try
'./configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib'
In some 64-bit environments, try LDFLAGS=-L/usr/local/lib64.

* 解决方法:`./configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib`
* `make`
* `make install`
* 最终生成的插件名字为`protoc-gen-swift`,会被安装到`/usr/local/bin/`目录下。
* 去看看
* `cd /usr/local/bin/ `
* `ls -a`

关于ProtocolBuffers-Swift的集成,推荐用Cocoapods集成,你也可以将该项目拖进你的工程直接使用,需要选中对应的库,编译,添加该库到工程,使用。

swift-protobuf版

这篇文章和上面一篇差不多,内容更多。

最后,原谅我没时间给大家抠图了!所以对于从来没有接触过的小白可能有些懵逼了!

上一篇 下一篇

猜你喜欢

热点阅读