Bobj-C
Bobj-C

Reputation: 5426

calling function in objective-c?

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

Upvotes: 0

Views: 944

Answers (1)

Kristopher Johnson
Kristopher Johnson

Reputation: 82555

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.

Upvotes: 5

Related Questions