Hi! So I am not really sure how all this works.
I want to use realtime data from the trains and buses in Sweden.
This is their page: https://www.trafiklab.se/api/
As I understand it I should use GTFS data which come in Protobuf format.
I think I must convert the Protobuf-data to Swift code. Not sure if this involves json.
One file I have has the extension .pb.
I tried to use this page:
https://medium.com/@andy.nguyen.1993/protobuf-in-swift-809658ecdb22
When I write this:
$ git checkout tags/1.1.1 $ swift build -c release -Xswiftc -static-stdlib
I get this error:
"error: 'swift-protobuf': the Swift tools version specification is possibly missing a version specifier; consider using '// swift-tools-version: 6.0.3' to specify the current Swift toolchain version as the lowest Swift version supported by the project"
As you understand I am really not sure what I'm doing. Maybe there is a better way?
Any help would be highly appreciated.
I want to use realtime data from the trains and buses in Sweden.
As I understand it I should use GTFS data which come in Protobuf format.
I think I must convert the Protobuf-data to Swift code. Not sure if this involves json.
Protobuf is a data transfer protocol invented by Google to support its online mapping services. It's now the de-facto standard for transferring vector data tiles.
It's likely that anyone using public transit data is going to want to map it. So Protobuf is a good choice because anyone doing mapping is probably already familiar with the protocol.
Protobuf has nothing to do with JSON. And you don't convert it to Swift. It's a long story.
I tried to use this page:
I really appreciate it when people include the URL to a tutorial they are trying to use. Thanks!
Unfortunately, that tutorial is over 6 years old now. While the general concepts haven't changed, it's unlikely that any of those command will work on modern systems.
Specifically, it is checking out an ancient version (1.1.1) of Swift-protobuf and then trying to compile it with a modern Swift toolchain, using obsolete build settings.
If you omit the "checkout tags" part, and drop the static build, then it will work fine.
However, there are still some significant problems you'll encounter. The Protobuf protocol itself is quite simple. Google's implementation of it is, like many such Google implementations, crazy, over-top-complicated. And Apple's Swift-protobuf project builds on top of that.
Google's own Protobuf implementation is on the list requiring a Privacy manifest. I don't know what's going on in there.
I can't provide any assistance with Google's or Apple's implementation. In theory, it's easy to incorporate a Swift package into an Xcode project. I don't know if that would apply in this case. And that tutorial pre-dates Swift packages anyway.
I would recommend you find a different Protobuf implementation. You might even need to look for one based in C or Objective-C. This kind of data serialization protocol isn't very friendly with Swift's static typing. That's one reason why this is all so complicated. To put it into perspective, I wrote my own Protobuf decoding logic with 300 lines of Objective-C code - including comments!