Filipe Mota
Filipe Mota

Reputation: 350

Google Protocol Buffers on iOS/Objective-C

I need help to configure/use protobuf in Objective-C for a iOS app. I've tried all but I keep getting errors on xcode. Did anyone manage to make protobuf work well in Objective-C/iOS?

Upvotes: 4

Views: 6061

Answers (1)

Krumelur
Krumelur

Reputation: 32597

I have used it to some extent on iOS, and with metasyntactic's extension, it works really well. I even managed to get the code generation as a custom build step in Xcode. We switched to Thrift for our project (for other reasons), so my apologies if some details below are wrong, but in general this is how to do it.

  1. In Xcode 4.2, open the target properties, go to the "Build Rules" tab and create a new build rule for "*.proto" files
  2. In "Using:", choose "custom script" and use a script like this:

    protoc --plugin=/usr/local/bin/protoc-gen-objc $INPUT_FILE_PATH --objc_out=$DERIVED_FILES_DIR

  3. In Output files, add the generated files (there should be two files, $(INPUT_FILE_BASE).pb.m and $(INPUT_FILE_BASE).pb.h.

  4. Add the .proto files to your project.

Upvotes: 3

Related Questions