This code is based on Stanford Open Course cs193p video record. (Objective-C)