-
Notifications
You must be signed in to change notification settings - Fork 722
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
Objective-C bridging #22
Comments
Happy to re-open discussion, because actual use cases and proposals are exactly what we need. @KieranLafferty has been working on an We haven't thought about how this interacts with the runtime and which parts of the Swift code we can reuse however, and mixed language environments seem like a good use case to keep in mind. I would definitely be in favor of a bridging solution, where we can reuse most of the runtime code and also share a single cache between languages. Passing dictionaries seems like the easiest option. Using a reflection-based library like Of course, typed model classes would be a lot nicer. And if we can have them initialize themselves from the corresponding The benefit of this over a stand-alone Objective-C implementation is that result parsing relies on Swift typing magic, so keeping that in Swift and then bridging to Objective-C on demand means we don't have to reimplement this. I'm also wondering if there is anything we can do to make bridging transparent by using |
I only included the dictionary example as a simple, hacky workaround that one can actually use now to have a general way of exposing . I think it's not the right way to go forward. Exposing the The proposal for ObjectiveCBridgeable is really awesome, very unfortunate that it is currently deferred. But, quoting the authors of the proposal:
I think that their conclusion (choice 1 being impractical) is not completely relevant in our case, as we have the option to generate that code. |
Although it is private and not well documented, it seems you should be able to use |
@KieranLafferty any update? |
Just as a heads up: Given that it's been a few years and Swift has finally reached ABI stability (and module stability when 5.1 lands), we've officially decided not to move forward with Objective-C code generation on our end. You're definitely welcome to work on it on your own, but at this point it's just not on the priority list for Apollo directly. Thanks very much for your patience, and sorry we weren't able to help here. I'm going to close this issue out. |
Co-authored-by: Anthony Miller <anthonymdev@gmail.com>
I'd like to partly re-open the discussion on #1 🙈
I understand that it makes the most sense to create a new codegen target for an Objective-C only environment instead of crippling the beautiful Swift version. One thing we came across though, is the need to have some kind of Objective-C bridging. I guess other projects, at least older ones, will come across this, too.
The goal is to write most part in Swift, but there are still some parts of the code/UI that are too costly to rewrite and that need data from the backend.
One general solution to expose model objects to Objective-C code would be to pass dictionaries, instead of the generated
GraphQLNamedFragment
struct
s to@objc
functions:This has a few downsides. One of them is that any type-safety and compile-time guarantees are completely lost.
Another one would be also generate Objective-C compatible model classes that can be initialized with the
GraphQLNamedFragment
struct
s.Let's discuss 🎱
The text was updated successfully, but these errors were encountered: