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?

Ben

Answers


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:

General Syntax:

#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.

Please check the link and Example


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


Need Your Help

using awk to grep from each bunch of multiple lines

regex shell awk

I have a log file which has bunch of lines, where each bunch is separated by blank lines. I want to grep certain lines (containing common pattern) from each bunch of line. Each bunch of line is abo...

Dojo: TypeError: dojo.byId(…).attr is not a function

javascript html dojo

Weird, line one works fine but line 3 give me TypeError: dojo.byId(...).attr is not a function. There is hidden fields that hold all student pair that as &lt;input type="hidden"

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.