How to generate swift files for protobuf

3.2k views Asked by At

I have .proto files from my employee. Now I need to connect to service with this proto instructions. As I understood I need to generate some files for my swift project for boxing/unboxing my messages. But I can't understand how to do this. I've found many instructions how to install protobuf.

Can anyone explain step by step what I need to do? Thanks in advance.

1

There are 1 answers

0
Kellen On

As per ProtocolBuffers-Swift's install instructions:

...

  1. git clone [email protected]:alexeyxo/protobuf-swift.git

  2. ./scripts/build.sh

  3. Add ./src/ProtocolBuffers/ProtocolBuffers.xcodeproj in your project.

Their page on CocoaPods includes some basic uses, as well:

message Person {
    required int32 id = 1;
    required string name = 2;
    optional string email = 3;
}

let personBuilder = Person.builder()
personBuilder.id = 123
personBuilder.name = "Bob"
personBuilder.email = "[email protected]"
let person = personBuilder.build()
println("\(person)")

person.data() //return NSData

...

var person = Person.parseFromData(bytes) // from NSData