dugla
dugla

Reputation: 12954

In Objective-C Can I Treat a Property As An Array?

In good ole C I can do this:

int array[5];
int *iptr = array;

I have an Obj-C class with an ivar:

    float   *m_quad;

exposed via a synthesized @propery:

@property (nonatomic) float *quad;

Is there anyway to do this:

float f = myClass.quad[2];

Assuming of course I have malloc'd and set values for m_quad?

Thanks,
Doug

Upvotes: 0

Views: 159

Answers (1)

Steven Kramer
Steven Kramer

Reputation: 8513

Should work of the bat. I have an ivar and property

float diffuseColor_[4];
@property (readonly, nonatomic) float* diffuseColor;

The property is not synthesized, but using a simple accessor I can write

- (float*) diffuseColor
{
    return diffuseColor_;
}


object.diffuseColor[3] = 1;

Upvotes: 2

Related Questions