-1

I am a passionated non-professional programmer and I'd say I'm an expert in php and MySQL - I am able to program an entire web application in php with the look and feel of an iOS app, but.... it's still a web app.

Many times I started with swift and Xcode in the last years. But because it feels so different to me and it feels like handling code in Xcode with Swifft changes very often (e.g. SwiftUI), I stopped every time.

I have a very cool app in mind, but I'm bored of the next php web app project and I really want to realize it in iOS. With that I am directly confused with how data is stored.

To use my skill, I could create a php API and a MySQL database and use http requests. Fair enough...

But what if the user has no internet connection? I think of having two databases - one on the device and one in the internet. I already did a to do list tutorial with core data and swift ui.

To have something to talk about:

When the app starts, there should be a listview with accounts. Each account has a unique id and users can add accounts when they share the unique id. With that, multiple users are able to access the same data item. One creates the account and the random unique id and another user can add the account item to his app.

Each account has as list of multiple users that are related to that account and each account has a list of transactions that can be created by each users.

Additionally I can decide which user I am. In php I'd use a dropdown with a list of users and I'd store the value of the selection in a session.

If it helps to understand, I add my database structure:

CREATE TABLE `pay_accounts` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `share_id` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `currency` (`currency`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `pay_transaction_users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `user` int(11) unsigned DEFAULT NULL,
  `amount` float DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `user` (`user`),
  CONSTRAINT `pay_transaction_users_ibfk_1` FOREIGN KEY (`user`) REFERENCES `pay_users` (`id`) ON DELETE SET NULL ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `pay_transactions` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `date` timestamp NULL DEFAULT NULL,
  `payer` int(11) unsigned DEFAULT NULL,
  `amount` float DEFAULT NULL,
  `purpose` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `payer` (`payer`),
  CONSTRAINT `pay_transactions_ibfk_1` FOREIGN KEY (`payer`) REFERENCES     `pay_users` (`id`) ON DELETE SET NULL ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;---------------

CREATE TABLE `pay_users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `account` int(11) unsigned DEFAULT NULL,
  `mail` varchar(255) DEFAULT NULL,
  `activity` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `account` (`account`),
  CONSTRAINT `pay_users_ibfk_1` FOREIGN KEY (`account`) REFERENCES `pay_accounts` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

My direct confusion is: In php it is very easy now to create a from with HTML and add the data to MySQL... in Swift I am completely lost on how to realize that project.

Asperi
  • 228,894
  • 20
  • 464
  • 690
T. Karter
  • 638
  • 7
  • 25
  • You can use CoreData in iOS, which might be good fit for you, but if it is something simple you want to store you can just store your objects to disk and read them when you need em – Ladislav May 06 '20 at 14:01
  • 1
    What exactly is your question? How to create a table view in Swift? How to do networking and parse data from a http request? How to maintain a local database? How to add a textfield or submit button? There are neat solutions for all of these things. I would recommend to start with a basic tutorial that does something similar to your app idea, and then come back with more specific questions. Here is a tutorial on how to create an app to view and manipulate data in a table view: https://developer.apple.com/library/archive/referencelibrary/GettingStarted/DevelopiOSAppsSwift/CreateATableView.html – Gamma May 06 '20 at 14:22

1 Answers1

0

In php it is very easy now to create a from with HTML and add the data to MySQL... in Swift I am completely lost on how to realize that project.

How would you realize that in HTML/ PHP? You basically create a form in HTML and on submit you send your data via POST/GET to your backend and PHP deals with the database connection.

You can use that same approach for your iOS app aswell. In iOS you can make easy HTTP request, with different http request types. Check this thread. So often you will need a authentication first, where you send your credentials from the app to your backend to verify the user.

Data from your backend can be send in JSON/XML whatever you prefer. You can easily parse that in Swift/ Objective C and create your objects in the app and show data. If you want to store that data locally, you do that. Is it a good approach for sure (offline/ caching). You have to decide wheather you app should work offline aswell or it shouldn't. Both is possible.

Data can be stored locally in your database/ or even use CoreData framework, which makes it really easy. If you fetch new data, merge it with the existing data and display both.

I have a little picture for you to show, but your approach is already fine. I build a "Instagram" iOS clone, with PHP in backend. It works fine.

enter image description here

E_net4
  • 27,810
  • 13
  • 101
  • 139
davidev
  • 7,694
  • 5
  • 21
  • 56