我必须在 Objective-C 类中实现一个 C 函数,该函数通常会被调用int main
(在它自己的文件中)。由于我不熟悉拼接代码,我需要知道如何在awakefromnib
or applicationDidFinishLaunching
来自可可部分。或者如果有更好的方法可以做到这一点,我正在倾听。
这是一个没有太技术性的示例:
// Cocoa Imports
#import "AppDelegate.h"
...
// C Inlcudes
#include <stdio.h>
// (int main had to change to something else obviously)
int dos () {
printf ("I'm a C program\n");
}
// (back to cocoa)
@implementation AppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
//[This is where I need my C function above to execute]
它的调用方式与 C 中的调用方式相同,您可以调用任何您喜欢的 C 函数:
// Cocoa Imports
#import "AppDelegate.h"
...
// C Inlcudes
#include <stdio.h>
// (int main had to change to something else obviously)
int dos (const char *filename)
{
printf ("I was passed '%s'\n", filename);
}
// (back to cocoa)
@implementation AppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
dos("/path/to/some/file");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)