Just as a convention, you shouldn't put curly braces around @implementation.
About your question: the problem I see with the way you're trying to assign you array has the following error:
When you initialize a new ObjC instance of an object, its instance variables are set to zero, so your array will be a[0] == a[1] == a[2] == 0. This is because the allocator will ask for heap memory the size of your object + its ancestors. But later in the code, you're trying to copy memory from the stack to the heap: the { 4, 5, 6} array is created on the stack, and array[] lives on the heap. Do you see the problem here? What I would do, if you insist in doing it this way would be the following:
// compile from command line with
// gcc -framework Foundation -g -Wall -o test test.m
//
#import <Foundation/Foundation.h>
@interface Bla : NSObject
{
int array[3];
}
- (void)checkArray;
@end
@implementation Bla
- (id)init
{
self = [super init];
if (self) {
// init here
int tmpArray[3] = { 4, 5, 6};
memcpy(array, tmpArray, 3 * sizeof(int));
}
return self;
}
- (void)checkArray
{
NSAssert(array[0] == 4, @"invalid array initialization (4)");
NSAssert(array[1] == 5, @"invalid array initialization (5)");
NSAssert(array[2] == 6, @"invalid array initialization (6)");
}
@end
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
{
Bla *bla = [[Bla alloc] init];
[bla checkArray];
NSLog(@"done");
[bla release];
}
[pool release];
return 0;
}
It's not the best way, and probably you want to stick to using malloc, but this way you won't have to free the array later. Also, keep in mind that doing it this way you won't be able to change the size of array[], doing so will get in trouble for sure :)