Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK, I have compiled up the following code at it works as expected.</p> <p><strong>FloatHolder.h</strong></p> <pre><code>@interface FloatHolder : NSObject { int _count; float* _values; } - (id) initWithCount:(int)count; // possibly look into this for making access shorter // http://vgable.com/blog/2009/05/15/concise-nsdictionary-and-nsarray-lookup/ - (float)getValueAtIndex:(int)index; - (void)setValue:(float)value atIndex:(int)index; @property(readonly) int count; @property(readonly) float* values; // allows direct unsafe access to the values @end </code></pre> <p><strong>FloatHolder.m</strong></p> <pre><code>#import "FloatHolder.h" @implementation FloatHolder @synthesize count = _count; @synthesize values = _values; - (id) initWithCount:(int)count { self = [super init]; if (self != nil) { _count = count; _values = malloc(sizeof(float)*count); } return self; } - (void) dealloc { free(_values); [super dealloc]; } - (float)getValueAtIndex:(int)index { if(index&lt;0 || index&gt;=_count) { @throw [NSException exceptionWithName: @"Exception" reason: @"Index out of bounds" userInfo: nil]; } return _values[index]; } - (void)setValue:(float)value atIndex:(int)index { if(index&lt;0 || index&gt;=_count) { @throw [NSException exceptionWithName: @"Exception" reason: @"Index out of bounds" userInfo: nil]; } _values[index] = value; } @end </code></pre> <p>then in your other application code you can do something like the following:</p> <p>** FloatTestCode.h **</p> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; #import "FloatHolder.h" @interface FloatTestCode : NSObject { FloatHolder* holder; } - (void) doIt:(id)sender; @end </code></pre> <p>** FloatTestCode.m **</p> <pre><code>#import "FloatTestCode.h" @implementation FloatTestCode - (id) init { self = [super init]; if (self != nil) { holder = [[[FloatHolder alloc] initWithCount: 10] retain]; } return self; } - (void) dealloc { [holder release]; [super dealloc]; } - (void) doIt:(id)sender { holder.values[1] = 10; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload