views:

123

answers:

2

I have: typedef float DuglaType[3];

@interface Foo : NSObject {

DuglaType _duglaType;

}

How do I correctly declare the property?

I tried:

// .h
@property DuglaType duglaType;

// .m
@synthesize duglaType = _duglaType;

But this spews errors.

What is the secret handshake for C++ typedefs to play nice with Obj-C properties? Thanks.

Cheers,
Doug

A: 

My work around is to bail on using @property and implement setter/getters:

// .h

  • (float *) duglaType;
  • (void) setDuglaType: (DuglaType)input;

// .m

  • (float *) duglaType {

    return &_duglaType[0];

}

  • (void) setDuglaType: (DuglaType)input {

    m3dCopyMatrix44f(_duglaType, input);

}

I guess typdef-ing an array give Obj-C headaches. No worries.

Cheers,
Doug

dugla
A: 

Typedef the array into a struct:

typedef struct
{
    float p[3];
} DuglaType;


- (DuglaType) duglaType
{
    return _duglaType;
}

- (void) setDuglaType:(DuglaType) input
{
    m3dCopyMatrix44f(&_duglaType.p[0], &input.p[0]); 
}
dreamlax