Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, I suggest getting rid of the ResultItem class. I would replace it with a method in controller class instead - in your case, move the calculateUniformDistribution method to the AppDelegate. Or at least move the calculateUniformDistribution to a proper Model class (the actual objects that your app is dealing with Cars, Buses, Airplanes whatever).</p> <p>As regards actually returning a dictionary and adding values, here is a simplified example, assuming you stick to your current pattern:</p> <p>In AppDelegate.m</p> <pre><code>self.ri = [[ResultItem alloc] init]; NSMutableDictionary* dict = [self.ri calculateUniformDistribution:(double)x1 withxMinus:(double)x2 withxAvg:(double)x3 withCount:(double)numberCounter]; [dict setValue:[NSNumber numberWithDouble:1.0] forKey:@"additionalKey"]; </code></pre> <p>In ResultItem.m</p> <pre><code>NSMutableArray* dimensionRandomArray = [[NSMutableArray alloc] init]; NSMutableDictionary* returningDict = [[NSMutableDictionary alloc] init] autorelease]; //calculation loop [newResultItem setValue:[NSNumber numberWithDouble:max] forKey:@"maxValue"]; [newResultItem setValue:[NSNumber numberWithDouble:min] forKey:@"minValue"]; [newResultItem setValue:[NSNumber numberWithDouble:avg] forKey:@"averageValue"]; [newResultItem setValue:dimensionRandomArray forKey:@"randomValueArray"]; [dimensionRandomArray release]; return newResultItem; </code></pre> <p>Notice the autorelease of returningDict and release of dimensionRandomArray. Also, you have to release self.ri afterwards. And if you want to keep the dict around in the AppDelegate, you have to add retain-release.</p>
 

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