美文网首页iOS开发技术技术文程序员
iOS如何使用Protobuf[未完待续...]

iOS如何使用Protobuf[未完待续...]

作者: LaiYoung_ | 来源:发表于2016-07-15 12:02 被阅读1296次

一:如何将Protobuf解析成oc文件

先把https://github.com/alexeyxo/protobuf-objc.git clone下来。
<部分摘抄至 https://github.com/alexeyxo/protobuf-objc.git >
然后:

  1. Check if you have Homebrew
    brew -v
  2. If you don't already have Homebrew, then install it
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  3. Install the main Protobuf compiler and required tools
    brew install automake
    brew install libtool
    brew install protobuf
  4. (optional) Create a symlink to your Protobuf compiler.
    ln -s /usr/local/Cellar/protobuf/2.6.1/bin/protoc /usr/local/bin
  5. Clone this repository.
    git clone https://github.com/alexeyxo/protobuf-objc.git
  6. Build it!
    ./scripts/build.sh

成功之后如下图所示

Paste_Image.png

再cd到ProtocolBuffer对应的文件路径,执行protoc --objc_out=./ *.proto命令
这样,proto文件就会解析成oc文件
如下图所示

Paste_Image.png

二:在项目中如何使用ProtoBuf解析成oc的文件

将解析好的oc文件copy进工程里面
此时会Build Failed 'ProtocolBuffers/ProtocolBuffers.h' file not found 说这个文件没找到
此时需要使用cocoapods来集成一个三方库ProtocolBuffers
cd到项目的目录 使用命令echo -e "platform :ios , 6.0 \n target 'YourProjectName' do \npod 'ProtocolBuffers' \n end " > Podfile
注意替换YourProjectName成你自己的项目名称
然后pod install

相关文章

网友评论

  • MMD_:你好 我最近在研究ProtocolBuffers 能加下你的联系方式吗

本文标题:iOS如何使用Protobuf[未完待续...]

本文链接:https://www.haomeiwen.com/subject/edsyjttx.html