“My Chinese Zodiacs” Submitted for Review

The long waited update to the Chinese Zodiac app is submitted for review. This update includes support for screens of iPhone X or later, and a redesign of the layout for easier access to the match feature.

In the process to update this app from version 1.0, many places of the code was refactored. First was to convert to Swift 4.2, then Swift 5. It wasn’t too difficult because Xcode does most of the conversion for you.

Then there was a major update to the storyboard. The “Add” button now takes you straight into adding a new person, where before you had to select whether to add a new person or start matching the list of friends. 2 weeks ago, the UITabBar was added on the bottom. Along with cute icons for each of the tabs on the tab bar. The pig graphic is the same pig used in the zodiac signs in the app, if that was not obvious. And the heart in the pig for the matching icon, its vector path is same as the heart shape on certain gift for a special someone this year.

Due to this change, lots of segues are removed, and hidden navigation bars are used to handle all of the inter-view controller navigation. Big, rounded-rectangle buttons will trigger the navigation actions. This is a huge improvement from version 1.0, because before, each button activated a new segue and a brand new UIViewController is created. This is a problem because if you navigate back and forth a couple of times, you would actually have a huge stack of view controllers held in memory, and eventually your iDevice will run out of memory and iOS will kill the app. This probably has something to do with memory cycles, and can probably be caught by using Instruments in Xcode. I say probably because I haven’t actually tested the app in Instruments. I should though. For next release, I promise!

Data Access for each person now has its own class “PersonDao”. It sounds like it is coming from Java, but I am indeed was just writing Java code at work last week.

Further more, the fetching of “persons” and the matching of list of “persons” is now in the background and will asynchronously update the UI once it is done.

Lastly, the UISegmentedControl has its default background color changed from white. The default color is gray, and it is not very pleasing to the eye when the text in front of them is white.

Here is a sneak peak!

In the next update. I’m planning to support iPads and easier birthday input.

Detecting Swift Versions in Online IDEs

As a young programming language, Swift changes frequently. It often brings us new features and deprecates old syntax. Sometimes when you run into an online IDE like LeetCode, HackerRank or Online Swift Playgrounds, you will often wonder: which version of Swift am I working with here? Well, look no further. This buddy on Stack Overflow uses a programmatic approach to determine the Swift version, quite cleverly. I’ve included the code below. 

Interestingly, Repl.it actually has the version number printed as soon as the IDE is initialized. Kudos for them!

#if swift(>=5.2)
print("Hello, Swift 5.2")

#elseif swift(>=5.1)
print("Hello, Swift 5.1")

#elseif swift(>=5.0)
print("Hello, Swift 5.0")

#elseif swift(>=4.2)
print("Hello, Swift 4.2")

#elseif swift(>=4.1)
print("Hello, Swift 4.1")

#elseif swift(>=4.0)
print("Hello, Swift 4.0")

#elseif swift(>=3.2)
print("Hello, Swift 3.2")

#elseif swift(>=3.0)
print("Hello, Swift 3.0")

#elseif swift(>=2.2)
print("Hello, Swift 2.2")

#elseif swift(>=2.1)
print("Hello, Swift 2.1")

#elseif swift(>=2.0)
print("Hello, Swift 2.0")

#elseif swift(>=1.2)
print("Hello, Swift 1.2")

#elseif swift(>=1.1)
print("Hello, Swift 1.1")

#elseif swift(>=1.0)
print("Hello, Swift 1.0")