一:如何將Protobuf
解析成oc文件
先把https://github.com/alexeyxo/protobuf-objc.git clone下來悦穿。
<部分摘抄至 https://github.com/alexeyxo/protobuf-objc.git >
然后:
- Check if you have Homebrew
brew -v
- If you don't already have Homebrew, then install it
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Install the main Protobuf compiler and required tools
brew install automake
brew install libtool
brew install protobuf
- (optional) Create a symlink to your Protobuf compiler.
ln -s /usr/local/Cellar/protobuf/2.6.1/bin/protoc /usr/local/bin
- Clone this repository.
git clone https://github.com/alexeyxo/protobuf-objc.git
- Build it!
./scripts/build.sh
成功之后如下圖所示
再cd到ProtocolBuffer
對應的文件路徑,執(zhí)行protoc --objc_out=./ *.proto
命令
這樣业踢,proto文件就會解析成oc文件
如下圖所示
二:在項目中如何使用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