Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate an global array containing floating numbers
    primarykey
    data
    text
    <p>I wanted to create 2 global arrays which can be updated during the run of the programme.In each update i add one element to zeroth position and deleted the last number I created the arrays as.... In the .h file.......... //////////////</p> <pre><code>@interface Shared : NSObject{ NSMutableArray *x; NSMutableArray *y; } @property (nonatomic,retain) NSMutableArray *x; @property (nonatomic,retain) NSMutableArray *y; +(Shared*)sharedInstance; @end </code></pre> <p>In .m file</p> <pre><code>staticShared* sharedInstance; @implementation Shared @synthesize x; @synthesize y; +(Shared*)sharedInstance { if (!sharedInstance) { sharedInstance=[[Sharedalloc]init]; } returnsharedInstance; } -(Shared*)init { self = [superinit]; if(self) { x=[[NSMutableArrayalloc] init]; x=[NSMutableArrayarrayWithObjects:@"0",@"0",@"0",@"0",@"0",@"0",@"0",nil]; y=[[NSMutableArrayalloc] init]; y=[NSMutableArrayarrayWithObjects:@"0",@"0",@"0",@"0",@"0",@"0",nil]; } returnself; } @end </code></pre> <p>Then i used to call them and re,ove and added elements using the following code....</p> <pre><code>[[shared sharedInstance].y removeLastObject]; [[shared sharedInstance].y insertObject:new_element atIndex:0]; [[shared sharedInstance].x removeLastObject]; [[shared sharedInstance].x insertObject:new_element atIndex:0]; </code></pre> <p>In the mean time i call these values and calculate an arithmetic value using an expression.</p> <p>This seems to work well. But it seems to be an inefficient way to handle floating point numbers which i store in it. As these arrays creates objects. Is there any easy method that i can create a global array containing specified amount of floating point numbers and update it during the run of the programm(array size is fixed) by deleting the last object, and call them back to do calculation?</p> <p>Please help me!</p> <p>EDIT 1 To sir deanWombourne ................................. I implement as you instructed! Can you please go through this and help me to correct 2 errors i get.</p> <p>IN the .h file</p> <pre><code>@interface Shared : NSObject{ @private float input[7]; float output[6]; } +(Shared*)sharedInstance; -(void)addNewInput:(float)input1; -(float *)input; -(void)addNewOutput:(float)output1; -(float *)output; @end </code></pre> <p>in .m file............</p> <pre><code>@implementation Shared -(id)init{ if((self =[superinit])){ for(int n=0; n&lt;7 ;++n) input[n]=0.00f; for(int n=0; n&lt;6 ;++n) output[n]=0.00f; } returnself; } -(void)addNewInput:(float)input1{ input[0]=input[1]; input[1]=input[2]; input[2]=input[3]; input[3]=input[4]; input[4]=input[5]; input[5]=input[6]; input[6]=input1; } -(float *)input { returninput; } -(void)addNewOutput:(float)output1{ output[0]=output[1]; output[1]=output[2]; output[2]=output[3]; output[3]=output[4]; output[4]=output[5]; input[5]=output1; } -(float *)output { returnoutput; } @end </code></pre> <p>When calling it</p> <pre><code>float reading= (accel_reading)/(1.165969038*1e5f); [[SharedsharedInstance] addNewInput:reading]; </code></pre> <p>Problems i get 1. In the implementation, it says incomplete implementation (it's a warning not an error) 2. How can i used a for loop to fill array values or is this way ok?</p> <p>Major problem i get, When i call it as shown above, program stops running telling Terminating application due to uncaught exception 'NSInvalidArgumentException', reason '+[SharedsharedInstance]: unrecognized selector sent to class 0x5780'</p> <p>Please help me through this...............</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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