iOS如何使用Protobuf[未完待續(xù)...]

一:如何將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對應(yīng)的文件路徑,執(zhí)行protoc --objc_out=./ *.proto命令
這樣,proto文件就會解析成oc文件
如下圖所示

Paste_Image.png

二:在項(xiàng)目中如何使用ProtoBuf解析成oc的文件

將解析好的oc文件copy進(jìn)工程里面
此時(shí)會Build Failed 'ProtocolBuffers/ProtocolBuffers.h' file not found 說這個文件沒找到
此時(shí)需要使用cocoapods來集成一個三方庫ProtocolBuffers
cd到項(xiàng)目的目錄 使用命令echo -e "platform :ios , 6.0 \n target 'YourProjectName' do \npod 'ProtocolBuffers' \n end " > Podfile
注意替換YourProjectName成你自己的項(xiàng)目名稱
然后pod install

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容