Learning about Objective-C

Coming back from an iOS Coding club, I realized the importance of knowing Objective-C as a developer for iOS. Club member Harrison recommended the CS193P course from iTunes U library, so today I gave it a go and went through two lectures.

The lectures are densely-packed with information, but it is absolutely wonderful that I can take notes after pausing the video, and playing at half speed over and over when something is hard to understand. Today I learnt that this programming language is more than 30-years old and it is a strict superset of the C language (Probably lots of others languages are too). It uses C-style header (.h) and implementation files (.m), and it certainly is syntactically weird compared to other languages like Java.

Objective-C differs from C in that, it is completely object-oriented, it adds syntax for classes and methods. Objective-C differs from other modern OO programming languages in that, it has a special way of implementing public and private properties: the public properties are declared inside the header file, whereas the private properties are in the implementation file. During implementation, the getters and setters of public properties are automatically generated unless otherwise overwritten. For memory management, it uses the so called “automatic reference counting”, meaning that as soon as there are no more “strong” pointers pointing to an instance in the memory, the memory it occupies is instantly freed, so you know exactly when things are released. Moreover, in Objective-C, when a pointer is pointing to nil, or null in other languages, the pointer will actually return 0 instead of crashing the program, which is very convenient.

In Objective-C, both square brackets and dot-notation are used to access the instance’s properties and methods, I got really confused until I learned today that, by convention, only use dot notation when accessing the instance’s setters and getters.

As an exercise, I made an app “Matchismo” that flips a playing card around: a random card is draw from a deck of card each time it is tapped. There is a temporary ugly label below showing how many flips have occurred. This app allowed me to really understand the underlying principle of the MVC design strategy – grouping code into model, the view, and the controller, and a set of rules of how one is communicated to another.

I believe Objective-C is really a necessity for any iOS developer, not only because Swift is still in development, but also because lots of code written for iOS are still in Objective-C. I’ll continue to learn Objective-C from the iTunes U library in the upcoming few days.

Networking and More Sketch

These two days I have been going to networking events, asking around about the iOS industry. Yesterday I actually have met another independent iOS developer named Adam. Boy, aren’t I glad! It turned out we had a lot in common. Although he used to develop web apps, he recently started to develop for iOS and he actually has an app in the app store “Deep Journey“. The app is a visualization tool for the Mandelbrot Set, implemented using Apple’s graphic library “Metal”. I was quite impressed that he is able to independently develop something like that.

At home, I have been learning from Caleb Stultz‘s lectures about using Sketch. Here what I have learnt: Working with layers, styles, shapes, masking images, proportional scaling objects, text following a path, shape boolean, making symbols from groups and exporting graphics for different screen sizes of any popular mobile device. Additionally, I have also gone ahead and followed his tutorials on how to design a chat app simply called “Chat”. From the looks of it, I think his designs are highly conforming to the iOS Human Interface Guidelines, which is essential in getting it approved for the App Store.

 

Sketching with Sketch

I heard lots about the app called Sketch, citing it the “industry standard” for designing UI in mobile apps. Luckily I found that it has a trial version, so I began learning to use it. It certainly didn’t disappoint me. Its snap and alignment features are very handy and simple to use. The design interface is simple, and as someone who loves shortcut keys, Sketch offers a separate hotkey for each of the most frequently used tools such as rectangle (R), line (L)  and text (T). After a UI has been designed, it can be immediately imported into Xcode for further development. Pretty cool!

iPhone 7
A screenshot of an iPhone 7 artboard designed in Sketch

Got the Date() Down!

Been working on the Chinese Zodiac app. First I have sketched out the app in a basic functional flow diagram, followed by the adding in the corresponding UI elements. Next, I moved on to try and code it, but ran into much difficulty as I am not yet familiar with Core Data and the highly strict and inflexible Navigation Controller. I had very little trouble revisiting UITableView and UIDatePicker, but most proudly, I figured out not only how to create a Date object from DateComponents, but also extract DateComponents from a Date object, with the still-new Swift 3. It may not sound too exciting too people, but somehow I feel a sense of power, after having able to manipulate time with code.

June3rd-ChineseZodiac
Wireframe of the Chinese Zodiac app

Interestingly, buttons in the storyboard are restricted to text-based buttons, so a common technique used for more graphical approaches is to overlay a text-less button on top of an UIView rectangle. Unfortunately UIViews can only be a rectangle, and I wanted them to be circles; the solution I came up was to make the UIView into a square, and code in its view.layer.cornerRadius as exactly half of the square’s side length. Although, this solution works when users run the app,  but doesn’t preview in the storyboard. This explains the yellow squares in the app wireframe screenshots.

While browsing for various topics about Swift, I came across a blogger/Swift educator named Bob Lee, who has been writing and teaching Swift and iOS development. His blog posts are amazingly comprehensive and complete. As he puts it:

I try to use analogy to explain iOS Development so that my 13-year-old sister may understand.

It’s nice to see successful peers in the field of iOS development. Perhaps one day I can meet with him and chat about iOS.

Monorail Apps is Registered!

Today I went ahead and registered the name “Monorail Apps” as a legitimate business in Ontario via the ServiceOntario site! The process was really intuitive and simple, but sadly it does not guarantee name protection, meaning, anyone can register their business with any name, even though if the name is identical to any existing ones. There’s more to do to be fully legalized as a business, but today is a good start.

With the “Master Business License”, I am able to obtain a DUNS number which is required by the Apple Developer Program if the seller is going to be labeled as the company name. The DUNS number application will take 30 days to process, just in time for my July 31st goal of first app submission.

Yesterday, I have dived into a little bit into UX Design and its five-step process. It starts with research and planning, getting all the data that is relevant to the project. As part of step 1, I came across a powerful tool called “persona”: it is when the designer devises hypothetical and real data about typical users from different background and age groups, identifying their needs and emotions while using the app. The second step is to sketch the app with all the necessary functionalities and their corresponding UI elements in flow chart format. The step I liked to call Step 2.5 is the when the details are filled and refined as more feedbacks are received. Step 3 is prototyping, this is when the app itself is made to the finest detail possible based on steps 1-2.5. Step 4 is when it goes beta, lots of testing and refining. And finally, step 5, the launch, which is in many cases, just a beginning of a new chapter. I plan to implement this process to the Chinese Zodiac Signs app.

Using Swift’s Own Chinese Calendar

After some more research about the Chinese calendar, I actually found out that the Swift library support many types of calendar, including the Chinese calendar. Since the Chinese calendar adds a leap month every three years as opposed to the Gregorian calendar’s leap day (Feb. 29th), the Calendar object actually has a boolean property “isLeapMonth” to determine whether or not the year has a leap month.

To convert Gregorian calendar to Chinese, first I instantiated a calendar using “Calendar(identifier: Calendar.Identifier.chinese)”. Then, one is able to create a DateFormatter object with this instance of calendar by assigning it to DateFormatter.calendar. Finally, I used the DateFormatter to nicely format any Date object into the corresponding Chinese calendar date using DateFormatter.string(from: Date).

With the math figured out, the next step is to sketch the app’s functions and UI in detail. Planning to finish that before the weekend!

June1-ChineseCalendar

The Chinese Calendar

Aside from attending my own graduation ceremony today, I have read some articles about the Chinese calendar which will be implemented for my next app that includes Chinese Zodiac Signs. I found out that the modern Chinese calendar is essentially a calendar that counts by synodic months, which are complete phase periods of the moon observed on earth (time between one new moon to the next). Synodic months average to about 29.53 days, so 12 synodic months are about 11 days short from earth’s rotation around the sun: 365.24 days. To make up for this difference, a “leap month” called the intercalary month is inserted every 3 years.

The Chinese calendar has 24 solar terms or in Chinese “节气” which are used to mark the change of seasons and weather patterns. As a result, the intercalary month recalibrates the prediction of these “seasonal markers” for the use of planning out crop plantation and harvesting. But that’s another topic at another time.

With this information, I can write very little code to determine the Zodiac Sign for any given year and not relying on hard-coded data or CSV parsers.