Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 201389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:11:41+00:00 2026-05-11T17:11:41+00:00

Ok, here goes. I’ve completed a Cocoa foundation-tool that calculates mean absolute deviation of

  • 0

Ok, here goes. I’ve completed a Cocoa foundation-tool that calculates mean absolute deviation of random integers (Just as a learning project).

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.

#import <Foundation/Foundation.h>

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...

}

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

-(float)findMeanAbsoluteDeviation:(NSMutableArray *)array {
    ...code...
}

and in my “mad.h” file.

@interface mad : NSObject {

}

    - (float)findMeanAbsoluteDeviation:(NSMutableArray *)array;

@end

seems all awesome. Right? all I have to do is add…

#import "mad.m"

to the top of my “main.m” file and use the function as I would normally. Well, it doesn’t seem to compile correctly.

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

“——” is omitted for length’s sake

Command /Developer/usr/bin/gcc-4.0 failed with error code 1

Any ideas? Thanks for your help!

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:11:42+00:00Added an answer on May 11, 2026 at 5:11 pm

    You want #import "mad.h", not #import "mad.m" otherwise the class implementation is evaluated twice, hence the error you’re seeing.

    A few stylistic points:

    • If you’re not using an object’s instance variables for anything, you typically write a class method (+) not an instance method (-).
    • There’s no problem declaring a C function prototype in an Objective-C header file, if a class interface doesn’t make sense for what you’re doing. See NSGeometry.h for some examples.
    • If you don’t mutate an array in a function or method, don’t use a mutable array parameter.
    • Consider using standard Cocoa naming conventions for classes, methods and functions.

    For example:

    @interface MEMeanAbsoluteDeviation : NSObject {
    }
    + (float)meanAbsoluteDeviation:(NSArray *)array;
    

    or simply:

    float MEMeanAbsoluteDeviation(NSArray *array);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, first question so here goes, A function that runs on activation of a
Not sure if im just being stupid or something but here goes i work
Here goes: I have an application that does some processing, writes some result files
First post, so here goes. I'm writing a script that does intelligent search and
I didn't see any questions that asked this previously so here goes: Once you
This is embarrassing, but here goes. Here's the page that I'm working on: www.mchenry.edu/administration/BoardSchedule.asp
this is kinda tricky to explain,but here goes....I have multiple hidden divs that swap
OK here goes, I am trying to write a script that, when a user
Here goes: I have a view that looks like this: public interface IAddressView {
Looking around I found nothing that addresses my issue so here goes. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.