You need a header file (.h) and a code file (.m)
The header file defines the interface to the class, i.e. the instance variables and methods defined by the class. Instance methods begin with "-", class methods begin with "+". Example:
/* Here is an example .h file, "CircularList.h".
All behavior is inherited from List, which defines a List of objects.
Nowdays we can use NSArray which is more complex than List.
*/
#include <objc/List.h> /* Superclass interface */
@interface CircularList: List /* List is superclass */
{
int currentLocation;
}
- next; /* Returns next object in List or nil if none. */
@end
/* Here is the corresponding .m file: */
#include "CircularList.h"
@implementation CircularList
- next
{
int numObjects = [self count];
if (currentLocation >= numObjects)
currentLocation = 0;
return [self objectAt:currentLocation++];
}
@end
|