Chaque fois que j'appelle la fonction doSomething, mon programme se bloque. Le code réel comme un peu de vérification des limites de tableau, donc je sais que ce n'est pas un problème.Objective-C: Comment créer une classe avec un tableau 2d C en tant que champ?
maClasse.h
#import <Foundation/Foundation.h>
@interface myClass : NSObject {
BOOL **myMatrix;
}
@property(readwrite) BOOL **myMatrix;
-(myClass*)initWithWidth: (int)w andHeight: (int)h;
-(void)doSomething;
+(BOOL **) createMatrixWithHeight: (int)h andWidth: (int)w;
@end
myClass.m
#import "myClass.h"
#import <Foundation/Foundation.h>
@implementation myClass
@synthesize myMatrix;
-(myClass*)initWithWidth: (int)w andHeight: (int)h {
self = [super init];
myMatrix = [myClass createMatrixWithHeight: h andWidth: w];
return self;
}
-(void)doSomething{
myMatrix[2][2] = YES;
}
+(BOOL **) createMatrixWithHeight: (int)h andWidth: (int)w{
BOOL **newMatrix;
newMatrix = malloc(w * sizeof(BOOL *));
int i;
for(i = 0; i < w; i++){
newMatrix[i] = malloc(h * sizeof(BOOL));
}
return newMatrix;
}
@end
Peut-être que vous devriez essayer d'exécuter avec malloc de garde lib. –