Image for post

Finally, I finished this eight-week course. As an iOS developer, naturally I chose iOS track.

Assignment 1: Pokedex


Add searching function.

Add a button to keep track of which Pokémon have been caught and save the state in UserDefaults.

Create structs with types that match the keys and types returned by the API. Parse the JSON data and display Pokemons’ image and description

Some structs are added to help parse the JSON data. I have done some practices of this skill in Music App, so it didn’t take me much time to finish the parts of displaying pokemon image and description.

To keep track of the state if a pokemon is caught or not, I save their names as keys and a bool value as their values in . …

Image for post

Key Points

  • Basic commands and operations
  • SQL data types
  • Making SQL queries in Python programmes
  • Multiple tables
  • SQL injection attack

Assignment: Houses


Write a programme that imports data from a CSV spreadsheet. For each student in the CSV file, insert the student into the table in the database.

While the CSV file provided to you has just a column, the database has separate columns for , , and names. You’ll thus want to first parse each name and separate it into first, middle, and last names. …

Photo by Markus Spiske on Unsplash

1. Create Date Object with Specific Dates and/or Times

To create a Date object with a specific date, let’s say October 10 2020, we can create from or .

Create From DateComponent

var dateComps = DateComponents()
dateComps.calendar = Calendar.init(identifier: .gregorian) = 10
dateComps.month = 10
dateComps.year = 2020
let date =
//Oct 10, 2020 at 12:00 AM

The time will automatically set to 12:00 AM if not specified.

Create From String

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM/dd/yyyy"
let dateStr = "Jan/20/2020"
let date = dateStr)
// Jan 20, 2020 at 12:00 AM

2. Parse Dates

This part demonstrates how to parse string-based and integer-based values we get back from API to Date objects.

ISO 8601

ISO 8601 is a global standard for representing date and time formats. The example shown below is the most common format of ISO 8601. …

Image for post

Key Points

  • Python basics
  • Demonstration of converting previous assignments from C to Python
  • Files
  • Features that C does not have

Assignment: DNA

I broke down this programme into a few small functions, dealing with the DNA database, the input DNA sequences, and the computation of DNA results respectively.


At the beginning of this programme, it checks the number of command-line arguments first. If the user does not pass 3 arguments on the command line, this programme exits.

If 3 command-line arguments are passed, this programme reads the database by calling function . The second command-line argument, supposed to be the file name of a database, is passed to this function.

Photo by Roman Bozhko on Unsplash

1. Date

Date is a specific point in time, independent of any calendar or time zone.

To create a date object initialised to the current date and time, simply write like this:

let date = Date()

If you run it on Playground, the Date object shown on live view might look a bit different from what it is printed out. That’s because the Date object shown on live view shows the current date and time of your system. When you print it out, it shows the date information in ISO 8601 format UTC time. …

Image for post

Key Points

  • Resizing array
  • Data structure
  • Linked list
  • Tree
  • Hash table
  • Trie
  • Queue
  • Stack
  • Dictionary

Assignment: Speller


Implement functions that spell-check a file after loading a dictionary of words from disk into memory. Use a hash table to keep track of the words in dictionary

load() Function

  1. Open the dictionary file
  2. Read words from the dictionary file one at the time
  3. Create a new node for each word
  4. Hash word to obtain the hash value (index of hash table)
  5. Check if the location of the hash table has a node yet. If yes, insert the new node at the front of the linked list. …

Infinite Scrolling View

One day I just wanted to make a collection view able to be infinitely scrolled both forward and backward, so I started to think about how to make it. Then I was inspired by those infinite rotating ads commonly seen on e-commerce apps.

Image for post

Key Points

  • Hexadecimal
  • Pointer: operator, operator
  • Dynamic memory allocation: ,
  • string: null terminating character
  • Compare & copy string
  • : check memory leak
  • function
  • Memory layout: heap, stack
  • Call stacks
  • File pointer: open, read, write, and close
  • JPEG & BMP

Assignment 1: Filter (less)


Complete functions , , , and that apply filters to BMPs.

Functions and simply iterate through each pixel and recalculate its RBG values. Function swaps the RGB values of each pixel with the pixel on the mirror side of it. These 3 functions are quite easy, so I don’t show them here.

Function is more complicated. It computes the new value for a pixel by taking the average RGB values of the old colour values of all 9 pixels (4 or 6 pixels if the original pixel is on the edge) that form a grid around the original pixel. …

Photo by Zhiyue Xu on Unsplash

Although Swift is widely used to develop iOS app today and you can even get an iOS developer job without knowing a bit of Objective-C, sometimes it’s still inevitable to face Objective-C, especially at work. You might be assigned the task of maintaining an old project or developing an app based on an old Objective-C project. Either situation could be quite challenging to a Swift programmer who barely knows Objective-C. So, a little knowledge of incorporating Swift into Objective-C might save you some trouble of dealing with it.

Import Swift Code File

Create a Bridging Header by Xcode

The first time you add a Swift file to an Objective-C project, this dialogue box will appear, asking if you would like to create a bridging header. Make sure you click Create Bridging Header, then Xcode will configure everything for you. …

Image for post

I thought we would be asked to implement sorting and searching methods we learned in week 3 in this week’s assignments, but it turned out the assignments have nothing to do with them😂

Since the problem sets are getting complex as entering week 3, CS50 provides predefined programme structure and breaks down the programme into small functions. All we need to do is to complete the functions that are left empty.

Assignment 1: Plurality


In a plurality election, every voter gets one vote, and the candidate with the most votes wins.


Complete the function. Validate the input name. If it matches one of the names of candidates, update that candidate’s vote and return true. …


Penny Ng

iOS developer/ Swift/ Objective-C

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store