In March of 2018 I accepted my wife’s challenge to publish an app in the App Store by the end of the summer, and I began porting my browser game High Castle to Swift and iOS. As of May, 2019, there’s good news and bad news.
The bad news: The end of the summer came and went, and the end of the year came and went, and I didn’t publish the app. Almost half of 2019 has gone by and I still haven’t published the app.
The good news: Even though the app isn’t published, it’s about ninety percent finished.
More good news: I learned a lot about Swift. Like how to compile and run Swift programs from the command line and how to work with JSON, and the differences between classes and structures. It’s one thing to read books and articles about Swift but it’s another thing entirely to implement a decent-sized program. I started by writing a model (as in MVC: Model View Controller) with a simple text user interface that runs from the command line. Then I hooked the model in to an iOS app.
Even more good news: After porting the game from JavaScript and HTML to Swift, I started work on a Java/Android version. As with the iOS version, I started by porting the model to Java. Porting the model from Swift to Java went faster than porting it from JavaScript to Swift, partly because I’m a lot more familiar with Java than I am with Swift, and partly because I had already figured out how to set up the command-line user interface.
MVC
The other thing that helped with the Swift-to-Java conversion is that I had a well-defined Swift model. I think I did a reasonably good job of separating the view and the model in the original JavaScript version, but there were still some things I had to figure out about exactly what should be in the model in Swift and how it should work. It also helped that Java is closer to Swift than Swift is to JavaScript, particularly in terms of types.
Web views
Web views have played a big role in the High Castle Challenge. The original JavaScript version used HTML and CSS for the entire user interface. Since iOS includes a web view component, I had three basic choices for the iOS version: use web views for all of the GUI, don’t use web views at all, or take a hybrid approach and use web views for some of the GUI but not all of it. I went with the hybrid approach.
There are two big advantages to using web views. The biggest advantage is that the JavaScript, HTML, and CSS used in web views can be used in all of the different platforms: the original HTML5 browser version, the iOS version, the Android version, and the JavaFX version. That means that once I have finished porting the model to a new platform, a lot of the work has been done because I just need to copy the JS, HTML, and CSS to the new app. Setting up the bridge between the native code and the JS code takes some work, but presumably that only needs to be done once for each platform.
The other advantage of web views is that it’s much easier for me to get things to look the way I want them to with HTML and CSS than it is with native GUI systems. I’m not an expert at web design, but I’ve done enough with HTML and CSS to know my way around and I can usually get things to look the way I want them to look. On the other hand, I don’t do a lot with GUIs on the mobile platforms or JavaFX, so anything beyond a basc screen can take a lot of time, be very frustrating, and still not end up the way I want it to be.
JSON
I used JSON a lot in the original browser version of High Castle. The board game version of High Castle uses a lot of cards, and JSON is a convenient data format for the cards. It goes without saying that JSON is extremely easy to use in JavaScript code. After all, the JS in JSON stands for JavaScript. JSON isn’t quite as easy to use in Python, but it’s still very easy. Swift and Java are another story.
I won’t go into all the messy details here, but the bottom line is that it isn’t conceptually difficult to work with JSON in Swift and Java, but it can be tedious, and I ended up writing a lot of code. Sigh.
What’s next?
In this post I’ve discussed a few of the main things I’ve had to figure out for the High Castle Challenge. In the coming weeks and months (and years?) I plan to write about each of these topics (MVC, web views, JSON) and others in a lot more detail and include plenty of sample code. Will that actually happen? Considering my past history of writing and posting articles, I’d have to say the chances aren’t particularly good. But I’m going to try. It’s all part of the High Castle Challenge.