andreipfeiffer / workshop-react-native-custom-modules

2 stars 11 forks source link

Suggestion: Add an example that returns JSON from Swift #1

Open elisechant opened 4 years ago

elisechant commented 4 years ago

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

Other

In response to your comment:

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.

andreipfeiffer commented 4 years ago

@elisechant thank you so much for this comment.

Besides JSON, what other (complex) types did you have to tackle?