In part 1, I gave a brief, high level overview on how Java web apps are written. Ok how about a quick recap of what was covered in part 1…actually let’s use some diagrams this time. In this post, I will talk about how to build iOS apps like Java mvc web apps that use Struts or Spring framework.
iOS apps like Java MVC web app … in Part 1
![]() |
| Java web app architecture |
The above diagram essentially summarises what was written in the section titled “Java web app walkthrough”, so in a nutshell
- For a Java web app, the user interface (UI) is created via HTML/CSS/Javascript
- The Controllers i.e. Java code act as a communication layer between the UI and the Data store, typically a Database: what that means is that the Java code passes data to and from the UI and the Data Store(Database). The kind of Data Store that I normally work with is a relational database, there is a reason I have mentioned the type of database, read on to find out why.
- Refer to Part 1 for a more detailed walkthrough of a real-world example of using a registration form
Now how can we apply the above approach to writing iOS apps?
How did I apply my front-end skills to my iOS app?
![]() |
| iOS app with a Java web-app like architecture! |
- UI: The UI is essentially an HTML5 interface presented via a UIWebView and I am using the Ionic framework to power(style/control) the UI.
- Swift code: These are essentially the ViewControllers and a set of Helper classes written in Swift that send data back and forth between the UI and the database.
- Data Store: Now this is interesting, because the “data store” for my iOS app is Core Data. Now the reason that data store is in quotes is because, Core Data is not really a relational database, in fact you are encouraged to not think of it in terms of a relational database. Have a read of this answer, to get an idea of what it is all about. Anyway, relational database or not, it is a data store i.e. a component for us to store and retrieve data.
iOS app lifecycle
- View: this is the view for our App i.e. what the user sees when our app is launched. Now the user (on the right with a nice smiley face), can interact with the View. The view can have many iOS controls or objects (UI stuff like buttons navigation panes etc), that you can drag and drop while developing in Xcode.
- WebView: For the sake of this post, let’s look at UIWebView as an example of a WebView control. We place the WebView onto the View such that it occupies the entire screen. So when the user is interacting with the view, the user is really interacting with the WebView.
- ViewController: The ViewController is basically a Swift class that facilitates communication between the DataStore and the View. wait what? ok how about an example; say, we store the user’s details in our iOS app’s Data store and the user expects to see those details in the view by the click of a button. Now the way that would work is,
- The user clicks a button in the view i.e. WebView, to see the details.
- The WebView will then let the ViewController know of the request that the user made.
- The ViewController retrieves those details from the Data store i.e. Core Data and passes it to the View
- The WebView then renders those details onto the screen so the user can see them
p.s. It is also possible to achieve the above on app launch i.e. on starting the app, the first thing the user expects to see are those details. Once again if you read the apple docs, you will see that there are methods that can be called when the app is first launched. This is out of the scope of this post, but I would highly recommend reading up on the AppDelegate. Having at least a basic understanding of the AppDelegate is very important when you are making your iOS app.
Summary
So like me, if you have some front-end skills and are starting to work on your first iOS app, adopting the approach described in this post means that you can reuse your front-end development skills, when you start making your iOS app. Awesome! right?
So what do we(readers) do with all this information?
If you are a Java developer like me, and are thinking of building an iOS app and have no iOS background knowledge, I would strongly suggest that you have a look at this Github repo. I released Html5StarterAppWithSwift Xcode project template to provide a means for developers to quick start building “native” HTML5 apps such that they can avoid some of my early struggles i.e. not get stuck at the same problems that I got stuck on in the early stages. You can also refer to one of my older blog posts about the Html5StarterAppWithSwift. The project template follows the methodology or app architecture described in this post. As a template for HTML5 based UI, I have used the Ionic framework and I have also added sample code (native Swift) for things such as setting, retrieving and cancelling local notifications.
As usual, if you find any of my posts useful support me by buying or even trying one of my apps on the App Store.
Also, if you can leave a review on the App Store or Google Play Store, that would help too.
[appbox googleplay com.mydaytodo.simplenotes]
[appbox appstore 1478331765]



0 Comments