开发者

calling function in objective-c?

let's say in a proje开发者_JS百科ct 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜