Note that there are some explanatory texts on larger screens.

plurals
  1. POreturn object from model class
    primarykey
    data
    text
    <p>I hope I don't get shaved here! I try to call a method within my model-class and return a object to the calling controller.</p> <p>my AppDelegate.h:</p> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; @class ResultItem; @interface AppDelegate : NSObject &lt;NSApplicationDelegate&gt;{ ResultItem *ri; } -(void)calculateResults; @end </code></pre> <p>my AppDelegate.m:</p> <pre><code>#import "AppDelegate.h" #import "ResultItem.h" @implementation AppDelegate //other stuff - (void)calculateResults{ self-&gt;ri = [[ResultItem alloc]init]; //ResultItem is my model [xx calculateUniformDistribution:(double)x1 withxMinus:(double)x2 withxAvg:(double)x3 withCount:(double)numberCounter]; } ... </code></pre> <p>my ResultItem.h</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface ResultItem : NSObject -(NSMutableDictionary *)calculateUniformDistribution:(double)xPlus withxMinus:(double)xMinus withxAvg:(double) xAvg withCount:(int) count; </code></pre> <p>my ResultItem.m</p> <pre><code>#import "ResultItem.h" @implementation ResultItem - (NSMutableDictionary *)calculateUniformDistribution:(double)xPlus withxMinus:(double)xMinus withxAvg:(double)xAvg withCount:(int)count{ NSMutableArray *dimensionRandomArray = [[NSMutableArray alloc] init]; NSMutableDictionary *newResultItem = [[NSMutableDictionary alloc]init]; //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"]; return newResultItem; } </code></pre> <p>The ResultItem method is called fine. I want to create a <code>NSMutableDictionary</code> object which I need to handle in my AppDelegate later on.</p> <p>My Question:</p> <ol> <li>How can I access the <code>newResultItem</code> within my <code>AppDelegate</code> method afterwards.</li> <li>I have no idea how to add more values with keys to the <code>newResultItem</code> within my <code>AppDelegate</code> method <code>calculateResults</code>. Can somebody help me with it please?</li> <li>Who is actually the owner of the <code>newResultItem</code> object <code>ResultItem</code> or <code>AppDelegate</code>?</li> <li>Does it looks wrong to setup the code like this. I try to follow the MVC pattern as best as possible.</li> </ol> <p>Please don't beat me up...</p>
    singulars
    1. This table or related slice is empty.
    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