My first iOS app using Swift

Sunday, June 28, 2020

Check out my app - The Simple Chess Clock - on the App Store!

Simple Chess Clock Screenshot

It has been three years since I graduated from my coding bootcamp (which is now defunct!) and a minute since I last posted. In the meantime, I took a new job with an awesome company called LeagueApps as a frontend engineer and have been building a lot of cool stuff and learning so much. I've been primarily working in the "frontend stack" of HTML, CSS, and JavaScript. It's really been the focus every day for me, and in my free time.

2020 has been a different year all around so far: equal parts difficult, exciting, and sometimes downright frustrating. At the start of the year, I committed to learning more about my craft, and in early March, I doubled-down on my commitment to improving my knowledge of coding and programming. I would have plenty of time to do so at home with no excuses.

For starters, I decided to try to gain exposure to other languages than the ones in which I work on a daily basis. Particularly, I wanted to learn a type safe language. I've only worked with dynamically typed languages, and even kicked off 2020 learning python for a couple months. I stumbled upon the "mypy" static typing option for python and that got me thinking: Typing is so important. I won't go into it here, but I feel that the benefits of using type safety greatly outweigh the costs. So, I set out to learn a language where typing is a feature, not an option.

Why Swift and iOS

First off, when deciding on what new language or technology to learn, I typically want something that is popular and growing as opposed to unpopular and dying. I perused Stack Overflow's 2019 Developer Survey Results as well as the PopularitY of Programming Language (PYPL) on GitHub. Stack Overflow's survey reveals Swift and Xcode among the post popular technologies available today and also lists Swift as one of the top-paying technologies. PYPL says Swift is the ninth (9th) most popular language as of June 2020.

I've always been keen on Apple products. I enjoy the design and ease of use of their devices. Mobile development always seemed kind of mysterious to me and I would often think "You need to really know what you're doing." It's no different than learning the browser part of programming. I just needed to set the foundation.

Coincidentally, around the same time, my company also hired an iOS engineer and I asked him about the development experience making Apple products. He made it sound straightforward, so I began learning Swift and iOS development in my free time, starting with Pluralsight's iOS app development fundamentals learning path. It was a completely different process than making an app for the browser, but it grew on me pretty quickly. That's when I decided to dive in and started making my first iOS app.

Here is a list of resources I used to learn Swift/iOS/Xcode:

What I built

I built The Simple Chess Clock.

This was essentially a learning project, so I wanted to 1) learn Swift fundamentals, 2) learn iOS/Xcode development fundamentals, and 3) push something through the App Store process and get the app live.

Because I like playing chess, I decided on making a chess clock, which would be an app that offered different chess clock options with different timing styles (such as a fischer clock) as well as adjustable preferences the user can change, such as the color of the clock buttons, a sounds that play after each turn, and showing/hiding text on the screen.

More complex things like networking would have made this a much longer foray than I wanted, so I stayed away from anything more involved - this was a learning project after all. There are a handful of issues/bugs (features?) that I might address, but I also might leave them as evidence of where I was at a moment in time to be used in comparison with future iOS apps I build.

chessclock-card.png

What I learned

Swift

Swift is pretty awesome. I come from a JavaScript background, and I was able to pick up on things quickly. But many things are different! Swift is ultra modern and has a very flexible, expressive syntax that makes it also very human readable. The real power lies in the fact that, inside of Xcode, your Swift code can practically write itself! Well, almost. You must of course write your own code, but Xcode is very helpful as you're typing.

Learning another language like Swift helped reinforce concepts I already knew, updated my thinking on others, and showed me plenty more that I have to explore.

Working in a type safe language, most of what I am starting to internalize is that everything has a type! Swift features type inference, meaning that you don't always have to explicitly state your types, because the Swift compiler can "infer" the type a lot of the time. When the compiler cannot infer, or your code is too ambiguous, Swift will let you know about it. I've also spent some time understanding and demystifying the Swift concept of Optionals (values that might have a value with a certain type, but also just might not exist at all and have a nil value), and how you unwrap them.

Sure, I completed an app with Swift and it's working - but I am definitely not using Swift's power to my advantage. I am not using enums, structs, and classes in the most Swift-y way, but again, that's why I did this app: to build a foundation.

Xcode/iOS development

Xcode is pretty sweet. The one thing I really like about Xcode is that it's truly a complete IDE. I started my career using Atom and then moved on to VS Code, which is what I currently use at work. Using storyboards in Xcode was a completely different approach than coding for the browser.

I focused on a few fundamental parts of developing an iOS app. I learned about the various ways to persist data in an app, and I opted for using a Property List to provide base configuration. The user could then alter that base configuration to suit their preferences. Learning how to access and then update a .plist was an adventure and probably what I spent most of my time on because it brought me to learning about the concept of an iOS app sandbox and the bundle, data, and iCloud containers they have. Once I understood the app sandbox more, accessing and using .plist 's for adjustable configuration made more sense!

Table views are ubiquitous in iOS apps. I thought I had to always use the "dynamic" approach to tables, where you provide an array of info that is then placed one item at a time into the table cells, but also made a huge discovery that you can make simple static tables as well, which is what I did for my settings part of my app.

I got familiar with using iOS app frameworks in general, and UIKit and AVFoundation in particular. I used UIKIt to create the UI, but also a timer for the clocks that are central to the app's chess clock functionality. I used AVFoundation to provide the option to play a sound upon each turn.

Oh, and App Icons: Apple is pretty big on those and it's not one size fits all. You need to create one that does not have a transparent background, and then you must make many different sizes for it. I used Draw.io to create a .png and then used a website called App Icon Generator that takes your image and spits out all the various sizes that Xcode requires.

App Store Connect process

App Store Connect, the place where you go and get your apps on the App Store (live, ready for sale) or TestFlight (the beta testing platform), is an important part of the process, obviously. It can be a bit time consuming if your app is complex. But overall, it's a fairly straightforward process that asks a lot of questions about your app.

You have to first join the Apple Developer Program. For individuals, that will cost you $100/yr to be able to add apps to the App Store or TestFlight. I'm going to call it "the price for greatness." Be ready to make various screenshots (images) of your app, which will be added to the rest of your app info make your little marketing page area in the App Store pop.

The biggest stumbling point for me was the Privacy Policy section. This is something that App Store Connect requires. At first, the legalese scared me, but I did some research on apps that don't collect any data at all (a.k.a. my app) and found some helpful guidance out there. Once you have your policy written out, you must provide a URL to to it. Think about this up-front because otherwise, when you're done with your app, you'll have to that much longer to see your app crush it in the App Store :) - so, think about a publicly-facing website readily available when you're ready to submit your app for review. I added a privacy page to my portfolio website.

What I liked

It's Apple, so you have to conform to the process and tools for making iOS apps with Xcode. Many people find this constraining and annoying. I didn't, and actually I enjoyed it quite a bit! I was also lucky that the Apple Worldwide Developers Conference 2020 (WWDC20) overlapped with my time developing this chess clock app - it gave me inspiration and a preview of what's to come from Apple. If you're not sure where to start with the WWDC20 content, start with the keynote and then move onto the platform state of the union video (each is ~2h long, so buckle in)!

Swift is an awesome language, but really only used for Apple platforms. If you're not interested in- or going to develop for Apple platforms, then chances are you're probably not going to learn Swift.

With Xcode, everything just worked. Sure, I hit my obstacles, but that's because I was getting used to the process and the frameworks available to me. Swift, when paired with Xcode, is really powerful and fun. It's easy to see your app in action even if you're not ready to spend money to get it on the App Store or TestFlight. You can view your app on your Mac via a simulator or your own Apple device connected to your machine.

App Store Connect process was a bit intimidating at first, what with the "Pay us money first!" and "Don't get into legal trouble!" messages (I'm exaggerating, it's not bad at all), but it was overall pretty straightforward and clear. It gets a lot more complex if your app uses third party libraries, stores/accesses/uses user data, or allows for in-app purchases.

What I want to learn next

In short, what I want to learn next is: everything!

In the WWDC20 keynote, Apple announced that they are going to be making and using their own Apple Silicon chips in forthcoming macOS machines, meaning that your iOS or iPadOS apps will be universal and can run on macOS. This has profound impact on how apps are made and the audience your one app can reach. I want to get ready for when this starts hitting the market late 2020.

I began at zero and put a simple app on the App Store in a month and a half. There's so much more I want to tackle the next time around, such as:

  • Improving my Swift fundamentals to unlock more powerful features and patterns that the language has to offer
  • Using more frameworks that utilize the features of the iPhone (camera, location, face ID, etc.), and use networking/API calls to get more interesting data into the app
  • Learning SwiftUI - the modern way to code apps across Apple platforms - to create the app as opposed to storyboards
  • Utilizing tests more - I didn't make any tests this time around
  • Feature other forms of data persistence - perhaps SQLite for more relational app-only things (like a to-do-list), or use CloudKit or Firebase for cloud-based storage.
  • Understanding how and when and use animations more
  • Making code sharable between projects (e.g. networking - if I'm making two apps that hit APIs, then I shouldn't be copying and pasting the same API fetching code into both apps)
  • Implementing some authentication/authorization - something I'm always trying to understand and get better at

I also am curious about what Apple actually does to "review" an app - no qualms with it, just curious as to the process.

Overall, it was very fun to learn Swift and make my first iOS app in Xcode. I can't wait to make my next one!