An implementation of Protocol Buffers for Objective C and Swift.
Protocol Buffers very compact data format for transporting over the internet. This compatible over REST and socket servers. They are very flexible for server end points that change frequently without breaking the client. Also the .proto files are a great way to document the server endpoints request and response with minimal work and auto generate serialization/deserialization on the client and the server.
The current implemenation uses an Objective-C port of Google's spec. In the future this will move to be a wrapper around the official C++ implementation for better performance while maintaining Swift compatibility.
Swift is supported as well with this libary via the native compability with Objective-C. Apple Swift/Object-C Docs
This project is based on an implementation of Protocol Buffers from Google. See the Google protobuf project for more information.
-
Copy the protocol buffer framework at
bin/Fat/ProtocolBuffers.frameworkto your project -
Add your .proto files (but don't include them in the compiled source). See Language syntax
-
Optionally add a Build Phase script to regenerate pb.h/pb.m files when releasing
if [
$CONFIGURATION == Release ]; then pushd $ {PROJECT_DIR}/protos/ /usr/local/bin/protoc --plugin=/usr/local/bin/protoc-gen-objc *.proto --objc_out=../src fi -
Include all the .pb.m files to your project to be compiled
-
Build your project in Xcode
In testing for Cocoa Pods. It's not been submitted to the central repo yet.
- added pre-compiled binaries for protoc and protoc-gen-obj
- added universal binary
- added ARC support for generated models
- added NSCoding and NSCopying to store directly to disk or keychain
- compiled with Maverick and works with Yosemite
Add the ProtocolBuffers.framework to your project. The library will work for iOS Simulator and iOS 7.0 on iPhone 4,4s,5,5s.
To generate protocol buffers model, create a .proto file, in terminal navigate to the bin/protobuf/2.5.0/bin directory and run protoc --objc_out=./ <your_folder_with_.protofiles>.
-
Install XCode and XCode command line tools
-
Install brew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" -
Install Autogen -
brew install autogen -
Install Automake -
brew install automake -
Install Google Protocol Buffers Compiler -
brew install homebrew/versions/protobuf250 -
Download ObjC Protocol Buffer Code Generation & Framework -
https://github.com/puppybits/protobuf-objc.git -
Either copy the precompiled objc code generation plugin for protocol buffers -
cp ./bin/protoc-gen-objc /usr/local/bin -
Or build it
./autogen.sh ./configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib make install
cd /folder/with/.proto files/ && protoc --objc_out=/my/output/folder *
Issue installing Protobufs 2.5.0 in Mavericks. Comment out the iosfwd.
#ifdef __DECCXX
// HP C++'s iosfwd doesn't work.
#include <iostream>
#else
#include <sstream>
//#include <iosfwd> // comment out this for the sstream
#endif
/usr/local/bin
protoc (file or symlink)
protoc-gen-objc (file or symlink)
/usr/local/include
needs a symlink called "protobuf" to /usr/local/Cellar/protobuf/2.5.0/include
/usr/local/opt
needs a symlink called "protobuf" to /usr/local/Cellar/protobuf/2.5.0
- Jon Parise [email protected]
- Cyrus Najmabadi (http://code.google.com/p/metasyntactic/wiki/ProtocolBuffers)
- Sergey Martynov (http://github.com/martynovs/protobuf-objc)
- Kenton Varda, Sanjay Ghemawat, Jeff Dean, and others