What is @interface UITableView (MyTableViewDelegate)
Im looking at some source code written by someone else and its intrigues me to see this line:
@interface UITableView (MyTableViewGestureDelegate)
Now I have previously seen only this:
@interface MyTableView : UITableView <MyTableViewGestureDelegate>
so I am a lil confused.
Any ideas as what to what im looking at?
It is a category declaration.
A category allows you to add methods to an existing class—even to one for which you do not have the source. Categories are a powerful feature that allows you to extend the functionality of existing classes without subclassing. Using categories, you can also distribute the implementation of your own classes among several files. Class extensions are similar, but allow additional required APIs to be declared for a class in locations other than within the primary class @interface block.
The declaration of a category interface looks very much like a class interface declaration—except the category name is listed within parentheses after the class name and the superclass isn’t mentioned. Unless its methods don’t access any instance variables of the class, the category must import the interface file for the class it extends:
#import "ClassName.h" @interface ClassName ( CategoryName ) // method declarations @end
Note that a category can’t declare additional instance variables for the class; it includes only methods. However, all instance variables within the scope of the class are also within the scope of the category. That includes all instance variables declared by the class, even ones declared @private.
There’s no limit to the number of categories that you can add to a class, but each category name must be different, and each should declare and define a different set of methods.
It is class category declaration - using categories you can split your class implementation into several files or add methods to existing classes.
MyTableView : UITableView < MyTableViewGestureDelegate > says your class MyTableView - subclass of UITableView - implements the protocol named MyTableViewGestureDelegate
UITableView (MyTableViewGestureDelegate) says you are creating a Category for the Class UITableView named MyTableViewGestureDelegate