Note that there are some explanatory texts on larger screens.

plurals
  1. PODeclare External Functions In A Cocoa / Obj-C Project
    primarykey
    data
    text
    <p>Ok, here goes. I've completed a Cocoa foundation-tool that calculates mean absolute deviation of random integers (Just as a learning project). </p> <p>I've moved the calculation into a function called "findMeanAbsoluteDeviation()" It accepts a NSMutableArray of NSNumber objects to preform calculations. Anyways. So this works all fine and dandy when I declare it in the same ".m" file as my other code.</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; float findMeanAbsoluteDeviation(NSMutableArray * array); int main (int argc, const char * argv[]) { ...generate random integers, execute function... meanAbsoluteDeviation = findMeanAbsoluteDeviation(numArray); } float findMeanAbsoluteDeviation(NSMutableArray * array) { ...mean absolute deviation maths... </code></pre> <p>}</p> <p>and it works fine. Now, I would like to move the function to an external file. I created a subclass of NSObject named "mad". I moved the function into my mad "mad.m", I read up and then re-formatted the declaration to look like</p> <pre><code>-(float)findMeanAbsoluteDeviation:(NSMutableArray *)array { ...code... } </code></pre> <p>and in my "mad.h" file.</p> <pre><code>@interface mad : NSObject { } - (float)findMeanAbsoluteDeviation:(NSMutableArray *)array; @end </code></pre> <p>seems all awesome. Right? all I have to do is add...</p> <pre><code>#import "mad.m" </code></pre> <p>to the top of my "main.m" file and use the function as I would normally. Well, it doesn't seem to compile correctly.</p> <pre><code>ld: duplicate symbol .objc_class_name_mad in ------standardDeviation.build/Debug/standardDeviation.build/Objects-normal/i386/mad.o and ------standardDeviation.build/Debug/standardDeviation.build/Objects-normal/i386/standardDeviation.o </code></pre> <p>"------" is omitted for length's sake</p> <pre><code>Command /Developer/usr/bin/gcc-4.0 failed with error code 1 </code></pre> <p>Any ideas? Thanks for your help!</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.
    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