如何在Obj-C应用程序中访问和使用dylib?

我做了一个包含以下代码的dylib:
    Test.h:

#import <Cocoa/Cocoa.h>
@interface Test : NSObject {
     int number;
}
-(void)beep;
-(void)giveInt:(int)num;
-(int)takeInt;

@end


Test.m:

#import "Test.h"

@implementation Test

-(void)beep {
     NSBeep();
}
-(void)giveInt:(int)num {
     number = num;
}
-(int)takeInt {
     return number;
}

@end
我编译了dylib并把它放在另一个项目中,但我似乎无法弄清楚如何从dylib创建一个Test对象并调用一些方法。 有人知道怎么做吗? 谢谢, 马特     
已邀请:
只是fyi:动态库在运行时加载。如果您不需要动态加载代码,请静态链接。 无论如何:
#import "test.h"
#include <dlfcn.h>

int main(int argc, const char *argv) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    void *handle = dlopen("test.dylib", RTLD_LAZY);
    id t = [[NSClassFromString(@"Test") alloc] init];

    [t beep];
    [t release];

    dlclose(handle);
    [pool drain];
}
你想要包含一些错误检查,但这是基本的想法。如果您想使用NSBundle(根据具体情况可能更“合适”),请参阅http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html)     

要回复问题请先登录注册