For non-counter integrations, having to parse and send real data between Swift and JavaScript is a reality.
However, a high frequency issue with Bridging is managing strict type resolution between Swift and Objective-C. Often response objects are nullified, such as if the data within them contain Optionals.
Proposal
I believe it would simplify the integration experience if we offered an advanced example that represented how to encode JSON response objects from Swift, in order to simplify output types and reduce the noise from Swift's Linter.
Similarly, we could decode objects received by Swift.
Another advantage to this is simplifying type casting in Objective-C. Whereby additional parameters would be cast simply to NSString.
Solution Aspects
JavaScript developers are familiar with he concepts of encoding and decoding JSON, as we use JSON.stringify and JSON.parse regularly.
to use a that either a JSON library pod dependency or a small inline function that developers can copy and paste to the top of their Swift Bridge file, requiring less overhead of knowing how to install a pod and require the dependency in the project.
Methods for JSON.encode and JSON.decode.
To not make assumptions that developers have control over Class inheritance for resources they might be using. ie, they not inherit Codable type.
Further, the mapping between ObjC and Swift is specific to iOS development and you can surely find resources online.
This is true, but I think it would be a more complete example and improve the developer experience. Seeing that your article and the examples in this repository is so comprehensive already, I think it would be beneficial to many.
Documenting my comment that I left on your fantastic article: https://medium.com/@elisechant/hey-andrei-wow-thats-so-kind-of-you-7f2195e3725a
Problem
For non-counter integrations, having to parse and send real data between Swift and JavaScript is a reality.
However, a high frequency issue with Bridging is managing strict type resolution between Swift and Objective-C. Often response objects are nullified, such as if the data within them contain Optionals.
Proposal
I believe it would simplify the integration experience if we offered an advanced example that represented how to encode JSON response objects from Swift, in order to simplify output types and reduce the noise from Swift's Linter.
Similarly, we could decode objects received by Swift.
Another advantage to this is simplifying type casting in Objective-C. Whereby additional parameters would be cast simply to
NSString
.Solution Aspects
JSON.stringify
andJSON.parse
regularly.JSON.encode
andJSON.decode
.Codable
type.Other
In response to your comment:
This is true, but I think it would be a more complete example and improve the developer experience. Seeing that your article and the examples in this repository is so comprehensive already, I think it would be beneficial to many.