Basics of Code Writing for iOS Apps

By Rajiv Ramnath

Let’s start with how to create a custom view in an iOS app. First, you have to add such a view to a scene. Then you will need to set the class of the view to a custom subclass using the Identity inspector. Of course, you will need to implement the class for this custom view.

In addition to the custom view classes, you need to write the code for the model and the controllers (or view controllers in iOS terminology).

Creating the game session view for an iOS app in development.

For all of these elements, you need to create Objective-C classes. To create a class, any class, follow these steps:

  1. Choose File→New→File.

    The set of file templates appears.

    New File screen in Xcode.

  2. Select Cocoa Touch and Objective-C class, then click Next

    A dialog box for naming the class appears.

  3. Name the class and set the superclass. Then click Next.

    A dialog box for saving the file appears. This dialog box also allows you to set the project target for the file

  4. Set the target of the file to be the current project and save the file in the project’s folder.

    Check the box next to the target to make the class you added a member of the target. Note that the default directory shown is the project’s folder. Just stay with the default.

    Saving an Xcode file in the computer files.

  5. Click Create.

    Two files are added to the project — an interface file (.h) and an implementation file (.m) — both with boilerplate code specific to the kind of class they represent (for example, the superclass of the new class).