pour apprendre

CédricJ

Membre confirmé
30 Décembre 2004
80
3
49
Nancy
bonjour les amis,
voilà je cherche une petit programme simple (type ouverture d'un fichier, recherche de chaine de charactéres, ...) réaliser avec les tools sous TIGER pour me permettre de comprendre comment ca marche et d'en faire à mon tour.
J'ai regarder "developer" mais je ne sais pas quoi utiliser c'est trop énorme !!
je ne sais pas par où commencer !!
j'ai de bonnes bases en programmation mais .... sous windows c, C++, ...
Merci d'avance,
Cédric
 
Bonsoir,
tu trouveras des tutoriels pour la programmation en Cocoa chez Project Omega.
Dans le répertoire Developer, les exemples de bases sont dans Examples/AppKit. (TextEdit par exemple)
Sinon, il y a un très bon bouquin pour apprendre la "philosophie" de Cocoa est "Cocoa par la pratique".
 
Un livre tel que "Cocoa par la pratique" est pas mal non plus pour découvrir les bases (je n'ai aucune action dans les éditions Eyrolles). Surtout que l'utilisation de "Interface Builder" n'est pas très simple au départ.
 
Bloc de code:
----------------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)

-----------------------------

c'est bien aussi de commencer par apprendre l'obj-c avant cocoa

voila l'exemple donné est "très c"

http://www.toodarkpark.org/computers/objc/

//base cpp windows
"l'obj-c ne permet ni la programmation non objet ni l'héritage multiple"

il va falloir aussi que tu révises ce qu'est un model view controller
car osx ce n'est que pro et propre et clean

+------------+
| Model |
+------------+
/\ . /\
/ . \
/ . \
/ . \
/ \/ \
+------------+ <------ +------------+
| View | | Controller |
+------------+ ......> +------------+

:zen: