LoginSignup
3
1

More than 5 years have passed since last update.

Swift - ProtocolBuffersをはじめる

Posted at

個人用のメモ書きです

環境

Swift: 4.0.3

protobufのインストール

$ brew install protobuf

Appleが提供しているプラグインを使う

$ git clone https://github.com/apple/swift-protobuf.git
$ cd swift-protobuf
$ git checkout tags/1.0.2
$ swift build

ビルドしたプラグインを指定して、.protoファイルをコンパイル

$ $ protoc --plugin=protoc-gen-swift=.build/debug/protoc-gen-swift --swift_out=. *.proto

パスを通しておく

$ mkdir ~/.protoc
$ cp .build/debug/protoc-gen-swift ~/.protoc/protoc-gen-swift
$ echo 'export PATH=$PATH:$HOME/.protoc' >> ~/.zshrc
$ source ~/.zshrc

Option

アクセス修飾子などの各種オプションは--swift-optで設定することができます。詳細は以下で確認できます。

参考

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1