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.
source to share
According to the installation instructions ProtocolBuffers-Swift
:
...
git clone git@github.com:alexeyxo/protobuf-swift.git
./scripts/build.sh
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
source to share