在OC文件中调用Swift相关方法时需设置
其中值为"项目名称-Swift.h",并在相关文件中导入#import "ObjecAndSwift-Swift.h"
Person类
@interface Person : NSObject
- (void)sayHi:(NSString *)name;
@end
@implementation Person
- (void)sayHi:(NSString *)name{
NSLog(@"sayhi %@",name);
}
@end
Swift方法,调用OC
public class Student: NSObject {
func sayHello(name:String) -> Void {
print("sayhello to \(name)")
let person = Person()
person.sayHi("lisi")
}
}
在OC中调用Swift
Student *sty = [[Student alloc]init];
[sty sayHello:@"PHP"];