Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 4 and Codable #84

Open
TofPlay opened this issue Oct 7, 2017 · 1 comment
Open

Swift 4 and Codable #84

TofPlay opened this issue Oct 7, 2017 · 1 comment

Comments

@TofPlay
Copy link

TofPlay commented Oct 7, 2017

Hi Maxim,
I really like the concept of FlatBuffers 😍
With Swift 4 you can create your own Encoder and Decoder to support the new codable feature of Swift 4. This will allow FlatBuffers to be used on a larger scale.
Here some resources to help you:

FlatBuffers should also be available on most environments. For that it would have to be a cross-platform component. 😉
To create a cross-platform component your can follow my tutorial Swift Cross Platform Framework or directly use my tool XcodeTool - Create a new component cross-platform

@mzaks
Copy link
Owner

mzaks commented Dec 11, 2017

Sorry for the very late response. Codable support can be introduced as a separate project based on the FlatBuffersBuilder and FlatBuffersReader class. However I don't see me doing it any time soon. First I don't have much experience with Codable and I also don't need it currently. That said I am also concerned with the semantics of Codable solution. In FlatBuffers the point of truth is the schema. In a Codable solution the point of truth becomes the class declaration itself. In order to support evolutions (change of type definitions) the user would have to be very careful, not changing the field declaration order, renaming but not removing the "deprecated" fields and adding new fields only at the end of the class definition. You might solve it by introducing some kind of KeyEnum where user can define mapping between property and the table index, but this seems much more complex to me than just using fbs files and do code generation.

I understand that the current way of code generating is opaque for Swift developers, this is why I started the code_gen branch (https://github.com/mzaks/FlatBuffersSwift/tree/code_gen) where I implemented FBS parser and code generator in Swift. Sadly it is not 100% done yet. I still do not cover the case with recursive table definitions, but everything else should work fine.

Also if anyone still wants to implement Codable solution I would gladly help, I just don't see myself doing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants