一:如何将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
对应的文件路径,执行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