How to create swift files for protobuf

I have .proto files from my employee. Now I need to connect to the service using these proto instructions. As far as I understood, I need to generate some files for my quick project to box / unpack my posts. But I cannot figure out how to do this. I found many instructions for installing protobuf.

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

+3


source to share


1 answer


According to the installation instructions ProtocolBuffers-Swift

:

...

  1. git clone git@github.com:alexeyxo/protobuf-swift.git

  2. ./scripts/build.sh

  3. Add ./src/ProtocolBuffers/ProtocolBuffers.xcodeproj

    to your project.



Their on CocoaPods also includes some basic uses:

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 = "bob@example.com"
let person = personBuilder.build()
println("\(person)")

person.data() //return NSData

...

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

      

+1


source







All Articles