0

We build the user interface (Swift) and algorithm (C++, which is going to create a mathematical problem and solve it) separately. We think that's because users are not necessary to download the computation part, so we want to do it in separated way. And now we are using Firebase as database. We can send, edit, delete data, all those sorts of things using Swift codes to interact with Firebase. And I know I can get JSON formatted information from Firebase. But after I get the information, how do I use those things to generate the solutions by C++ codes and send them back to the Firebase, so that the users can get the results?

I'm using a C++ mathematical API to do the computation. What should I do to interact with Firebase? Should I create an Objective-C++ environment and then talk to the Firebase directly? Or use Node.js to do the receiving data works from Firebase and transfer to either C++ or Objective-C++ and then send those things back to Firebase?

What I know so far is more like one-side communication. Like, users -> Firebase -> users. But what I need is, users -> Firebase -> mathematical computation -> Firebase -> users.

Am I thinking it in a right way?

Flynn Hou
  • 429
  • 1
  • 6
  • 18
  • Are you using Swift to pull the data from Firebase and then pass it to the C++ API? If so, then pass the results from the C++ API back to Swift and push the data to Firebase for user consumption. – Jay Oct 08 '16 at 16:25
  • @Jay How do I pass the data to C++ API? Does my C++ API have to set up the Firebase C++ SDK? – Flynn Hou Oct 10 '16 at 09:45
  • No. Use Swift to interface with Firebase - it can handle the push and pull. Once Swift has retrieved the data from Firebase, Swift can hand it off to the C++ API for processing. When that's complete the C++ API should hand the final resulting data back to Swift so it can be written to Firebase. You can't use C++ directly with Swift but a simple Objective-C wrapper will enable it's use. See this question and answer for details [Interacting with C++ classes from Swift](http://stackoverflow.com/questions/35229149/interacting-with-c-classes-from-swift) – Jay Oct 10 '16 at 16:56
  • @Jay OH I see! But right now I separate the C++ API away from the swift project. Could this way be doable? Or should I just put the Objective-C++ codes into the same project? What about setting up a server for doing the job what the C++ API does, and then interact with Firebase? – Flynn Hou Oct 10 '16 at 17:07
  • It really depends on your use case but in general you can wrap the C++ code up and use it right within your Swift project - that will make the whole flow much simpler to implement and much easier to update and troubleshoot . You could optionally offload the C++ module to another server but that may be only for extreme cases - like a distributed computing project (SETI) for example. – Jay Oct 10 '16 at 17:18
  • @Jay What about I implement my API by using Java, and then connect to Firebase to retrieve and save data? Sorry for my continuous questions. – Flynn Hou Oct 11 '16 at 03:17
  • My best advice is to keep it simple and use a modular approach: Use Swift to handle interacting with Firebase (the Firebase module), the UI (the UI module) and C++ for processing (the C++ module). If you start throwing too many components into the mix the code becomes unwieldy and hard to maintain. – Jay Oct 11 '16 at 17:44

0 Answers0