----------------AEList.h-------------
#import <Cocoa/Cocoa.h>
@interface AEList: NSObject
{
int list[100];
int size;
}
- free;
- (unsigned long) additem: (unsigned long) num;
- print;
- init;
@end
-----------------------------
----------------AEList.m-------------
#import "AEList.h"
@implementation AEList
+new
{
printf("AEList.new : new AEList object %i\n",self);
self=[super new];
return self;
}
- free
{
printf("AEList.free : dealloc AEList object %i\n",self);
[super dealloc];
}
- (unsigned long) additem: (unsigned long)num
{
list[size++]=num;
return size;
}
- print
{
int i;
for (i=0;i<size;++i)
{
printf ("AEList.print : Item[%i] = %i\n",i,list[i]);
}
return self;
}
-init
{
size=0;
printf("AEList.init : init AEList object with size %i\n",size);
return self;
}
@end
---------------------
----------------AElistExample.m-------------
#import "AEList.h"
int AElistExample()
{
id AElistExample;
int j;
printf ("\n----- AElistExample : new \n");
AElistExample = [AEList new];
[AElistExample additem:(unsigned long)5];
printf ("\n----- AElistExample : print = %i\n",5);
[AElistExample print];
[AElistExample additem:(unsigned long)6];
[AElistExample additem:(unsigned long)3];
printf ("\n----- AElistExample : print + %i , %i\n",6,3);
[AElistExample print];
for(j=0;j<5;++j)
{
[AElistExample additem:(unsigned long)j];
}
printf ("\n----- AElistExample : print + while %i to %i\n",0,5);
[AElistExample print];
printf ("\n----- AElistExample : free \n");
[AElistExample free];
return (int) AElistExample;
}
-----------------------------
-------------main.m----------------
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
int list=AElistExample();
printf("\nmain : return ID %i\n\n",list);
return list;
}
-----------------------------
-----------------Makefile------------
# Objective-C .m suffix.
.SUFFIXES: .o .m
.m.o:
$(CC) -c $(CFLAGS) $<
# Macros
CC = gcc
CFLAGS = -g
LIBS = -framework Cocoa
SRC=main.m AEList.m AElistExample.m
OBJ=main.o AEList.o AElistExample.o
PROG=listExample
all: hist
# Explicit rule
hist: $(OBJ)
$(CC) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS)
# Implicit rules
List.o: AEList.h AEList.m
AElistExample.o: AEList.h AElistExample.m
main.o: AEList.o AElistExample.o main.m
# Clean rule
clean:
rm -f *.o $(PROG)
-----------------------------