views:

73

answers:

1

Hello all,

let's say in a project there are 1.h, 1.m, 2.h and 2.m if i have a function inside 2.m how can call it from 1.m

Thanks Bob

+5  A: 

Calling a "function" is just like in C.

If you mean "How do I call a method of an object", then it's something like this:

// 2.h

@interface MyMailer

-(void)SendMail();

@end

// 2.m

#import "2.h"

@implementation MyMailer

-(void) SendMail()
{
    printf("My function has been called\n");
}

@end

// 1.m

#import "2.h"

void foo()
{
    MyMailer *mailer = [[MyMailer alloc] init];
    [mailer SendMail];
    [mailer release];
}

The Wikipedia article on Objective-C has some similar examples.

Kristopher Johnson
Hello, first thank for your answer but I wrote my function in objective-c language but i think ur code in "C" I can't convert my code to "C" so can u help me in Objective-c ??
Bobj-C