0

I have a website that uses MySQL database. I'm trying to build an iOS app for it, so I wanted to use Swift to import information from the database and insert new information to it. I read that for the reading part I should use a PHP file to create a Json file, read that and extract the data. But I can't find the way to do it with swift.

Is there a way to connect iOS apps (written in Swift) to MySQL?

user3187759
  • 187
  • 1
  • 16

1 Answers1

1

In the client-server architecture, the client is completely separate from the server, and they just exchange data thanks to a common "language" (in your case, certain fields encoded in JSON).

Your client is your iPhone app, written in Swift (but that's irrelevant).
You now need to build a server, which is entirely separate from the app. You don't need Swift for that. You will need a server (for example a cheap cloud VPS on Amazon EC2, Rackspace Cloud Servers, Microsoft Azure...) and you will have to create another application that runs on that server.

If it's just to pull data from a MySQL database, you can easily make that in PHP. Or you could use Node.js (which uses JavaScript: it's among the "trendiest" technologies at the moment), Ruby, Python, etc.
For an example that uses PHP, you can check: https://stackoverflow.com/a/22367600/192024
To read the JSON data in your iOS app, then, you can use the builtin libraries: https://developer.apple.com/library/ios/DOCUMENTATION/Foundation/Reference/NSJSONSerialization_Class/index.html (it's available in Swift too)

I don't know what your app is doing, but if you want to ignore all the things with the backend (the server) you can always consider something like Parse Core and let somebody else take care of the backend.

Community
  • 1
  • 1
ItalyPaleAle
  • 7,185
  • 6
  • 42
  • 69
  • I don't know how much the OP knows about developing in PHP (or server side developing in general) so I think it's a good idea to mention that for developing you can use a server like XAMPP or Apache Tomcat, avoiding fees until you go in production mode. – martskins Oct 09 '14 at 19:25