Apple swift - How can an app connect to existing heroku/S3 database

amazon-s3, ios, swift

Solution

Connecting an iOS app to a public database would really be a bad idea - all server logic should be implemented on the client, and you would also need to hardcode database user name and password in your app.

A better way is to create a server app exposing a set of REST APIs and being responsible of dealing with the database. This way you can better control at server side what the app client is able to do on the database.

If you have an order entry app, for instance, you can create APIs to:

- login

- register

- create an order

- modify an order

- add a contact

- delete a contact

- etc...

Some of the advantages are that:

- in case you need to update the logic (but not the API interface), you just need to update the server, whereas in your scenario you'd need to release a new version of the mobile app

- you control and limit how client apps access to the data (preventing for instance a user to access another user's orders)

- if you want to develop the same app in another platform (android, ...), you reuse the same APIs

To get started, I'd suggest you to read the AFNetworking tutorial on raywenderlch.com, focused on a ios networking library, but talking about JSON, REST, remote APIs etc.

Next you have to choose a server side technology - the most popular nowadays is node.js - to get started you can read other tutorials on the same website:

- http://www.raywenderlich.com/61078/write-simple-node-jsmongodb-web-service-ios-app

- http://www.raywenderlich.com/61264/write-ios-app-uses-node-jsmongodb-web-service

if you don't want to use node.js and/or mongodb... the same architecture applies, just languages and technologies differ. Just transpose what you learn from there.

If you want to read about other languages to use at server side, just google for it - if you want to use ruby, try with `ios rest api server ruby`.

Note: I made no mention of `swift` because your question looks more like an architectural problem than a language specific problem. The tutorials I mentioned here use objective-c, once you've designed an architecture and chosen the language at server side, you can start looking into how to call REST API from swift.

Problem

Im new to iOS and new to SWIFT with no previous experience with Obj-C. But, Im not new to Ruby. I have a web based app on heroku and am beginning to learn SWIFT so I can build an iOS counterpart. I need to wrap my head around the bigger picture before I can get started and I can not figure out how these apps connect to databases. Can an iOS app connect to an S3 database...and share that database with a website? Is there documentation on this process that I have over looked.

Original source