6_Objective-C Extensions

Extensions are actually categories without the category name. It’s often referred as anonymous categories.

The methods declared by a class extension are implemented in the implementation block for the original class, so you can’t, for example, declare a class extension on a framework class, such as a Cocoa or Cocoa Touch class like NSString..

@interface ClassName ()

Characteristics of extensions

  • An extension cannot be declared for any class, only for the classes that we have original implementation of source code.
  • An extension is adding private methods and private variables that are only specific to the class.
  • Any method or variable declared inside the extensions is not accessible even to the inherited classes.

Example of extension

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s