I'm trying to create a C array of objective C NSStrings using malloc. I'm not doing it right, but I don't think I'm far off. Maybe someone can point me in the right direction. Let's say we want 5 strings in our array for the sake of argument.
Interface:
@interface someObject : NSObject {
NSString **ourArray;
}
@property () NSString **ourArray;
@end
Implementation:
@implementation someObject
@synthesize ourArray;
-(id)init {
if((self = [super init])) {
self->ourArray = malloc(5 * sizeof(NSString *));
}
return self;
}
-(NSString *)getStringAtPos3 {
if(self.ourArray[3] == nil) {
self.ourArray[3] = @"a string";
}
return self.ourArray[3];
}
@end
When I set a breakpoint in getStringAtPos3 it doesn't see the array element as nil so it never goes into the if statement.