<

Objective C Basics

>

Objective C

The language used in iOS development is Objective C a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. It is the main programming language used by Apple for the OS X and iOS operating systems It is an object oriented language.

Objective-C source code program files usually have .m filename extensions.
Objective-C header files have .h filename extensions.

Interface and Implementation
In objective C the file where the declaration of class is done is called the interface file and the file where the class is defined is called the implementation file.

Header (.h)

In computer programming, a header file is a file that allows programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers. Programmers who wish to declare standardized identifiers in more than one source file can place such identifiers in a single header file, which other code can then include whenever the header contents are required. This is to keep the interface in the header separate from the implementation. [1]

Implementation (.m)

the implementation (method) files, normally suffixed .m. The actual code is written in the implementation file. Implementation (method) files normally have the file extension .m, which originally signified "messages".

AppDelegate.h

  • Header File that provides all User Interface (UI) related items.

.h files

  • Headder files, in objective-c, typically contain the classes @interface section with all the instance variables, property declarations, and method prototypes. Think of it like an outline of an essay. It has all the bullet points, while the paper itself has all the content.

 

AppDelegate.m

 

  • Imports the class Appdelegate's interface
  • Imports the viewcontroller to be loaded

ViewController.h/m

  • Interface for class ViewController
  • ViewController.h/m define a view controller class that manages a hierarchy of views -- basically, one screen of an application. You might have multiple screens that each have their own view controller.

ViewController.m

ViewController.xib

AppDelegate.h/m

  • AppDelegate.h/m define a class that manages the application overall. The app will create one instance of that class and send that object messages that let the delegate influence the app's behavior at well-defined times. For example, -application:didFinishLaunchingWithOptions: is sent when the app has finished launching and is ready to do something. h/m is responsible for the life-cycle of your application. What to do when the user press the home button and exit your app, what to do when the app enters the background.

AppDelegate is usually contains the following:

  • initialization: whatever needs to be done on the very first launch (after an install or an update)
  • data migration from version to version (e.g. if you use CoreData and migrations)
  • configuration of objects linked via IBOutlets from MainWindow.xib
  • determining the initial orientation to launch in
  • saving uncommitted data / state prior to the application being terminated or entering background mode
  • registering for the Apple Push Notification Service and sending the device token to our server
  • opening one of the supported application URLs (e.g. maps://)